]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
customize parallel transfer count
authordavidejones <david@davidejones.com>
Fri, 3 Mar 2023 16:52:31 +0000 (16:52 +0000)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 7 Mar 2023 14:38:26 +0000 (15:38 +0100)
commands/deploy.go
commands/hugo.go
deploy/deploy.go
docs/content/en/commands/hugo_deploy.md

index 071e10a6a3e108fd7bf899ae085b9a7bc500dc96..3a717201ecac282e3ba3283e51ab08833d6ba7d7 100644 (file)
@@ -31,6 +31,7 @@ type deployCmd struct {
 
        invalidateCDN bool
        maxDeletes    int
+       transfers     int
 }
 
 // TODO: In addition to the "deploy" command, consider adding a "--deploy"
@@ -59,6 +60,7 @@ documentation.
                        cfgInit := func(c *commandeer) error {
                                c.Set("invalidateCDN", cc.invalidateCDN)
                                c.Set("maxDeletes", cc.maxDeletes)
+                               c.Set("transfers", cc.transfers)
                                return nil
                        }
                        comm, err := initializeConfig(true, true, false, &cc.hugoBuilderCommon, cc, cfgInit)
@@ -79,6 +81,7 @@ documentation.
        cmd.Flags().Bool("force", false, "force upload of all files")
        cmd.Flags().BoolVar(&cc.invalidateCDN, "invalidateCDN", true, "invalidate the CDN cache listed in the deployment target")
        cmd.Flags().IntVar(&cc.maxDeletes, "maxDeletes", 256, "maximum # of files to delete, or -1 to disable")
+       cmd.Flags().IntVar(&cc.transfers, "transfers", 10, "number of file transfers to run in parallel. defaults to 10")
 
        cc.baseBuilderCmd = b.newBuilderBasicCmd(cmd)
 
index 2fa08ec21e5f797a2bffac38eb9daac0d4b20e21..156aa35b9241e1b423bdfdaa59e7594551f4df59 100644 (file)
@@ -236,6 +236,7 @@ func initializeFlags(cmd *cobra.Command, cfg config.Provider) {
                "target",
                "theme",
                "themesDir",
+               "transfers",
                "verbose",
                "verboseLog",
                "duplicateTargetPaths",
index 5675d7aa04f98b85d8310854c78c4da4ae3ed103..e2a12ca7f07f0b517d5604e86bbd36a1d6197239 100644 (file)
@@ -65,6 +65,7 @@ type Deployer struct {
        force         bool             // true forces upload of all files
        invalidateCDN bool             // true enables invalidate CDN cache (if possible)
        maxDeletes    int              // caps the # of files to delete; -1 to disable
+       transfers     int              // The number of file transfers to run in parallel
 
        // For tests...
        summary deploySummary // summary of latest Deploy results
@@ -118,6 +119,7 @@ func New(cfg config.Provider, localFs afero.Fs) (*Deployer, error) {
                force:         cfg.GetBool("force"),
                invalidateCDN: cfg.GetBool("invalidateCDN"),
                maxDeletes:    cfg.GetInt("maxDeletes"),
+               transfers:     cfg.GetInt("transfers"),
        }, nil
 }
 
@@ -189,7 +191,7 @@ func (d *Deployer) Deploy(ctx context.Context) error {
        // Apply the changes in parallel, using an inverted worker
        // pool (https://www.youtube.com/watch?v=5zXAHh5tJqQ&t=26m58s).
        // sem prevents more than nParallel concurrent goroutines.
-       const nParallel = 10
+       nParallel := d.transfers
        var errs []error
        var errMu sync.Mutex // protects errs
 
index 4e1d468b7c3d4e8c54d0eafe14879afdb2d4fcb5..c3cb9f68dd7015d6907347dcee3048323c3a38c3 100644 (file)
@@ -31,6 +31,7 @@ hugo deploy [flags]
       --ignoreVendorPaths string   ignores any _vendor for module paths matching the given Glob pattern
       --invalidateCDN              invalidate the CDN cache listed in the deployment target (default true)
       --maxDeletes int             maximum # of files to delete, or -1 to disable (default 256)
+      --transfers int              number of file transfers to run in parallel (default 10)
   -s, --source string              filesystem path to read files relative from
       --target string              target deployment from deployments section in config file; defaults to the first one
       --themesDir string           filesystem path to themes directory