Merge pull request #42 from stephensxu/feature/allow_dynamic_concurrency

add flag to allow user set dynamic concurrency instead of using hardcoded number
This commit is contained in:
Thomas Boerger 2018-08-15 20:37:01 +02:00 committed by GitHub
commit d22af6277e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -116,6 +116,13 @@ func main() {
Name: "env-file", Name: "env-file",
Usage: "source env file", Usage: "source env file",
}, },
cli.IntFlag{
Name: "max-concurrency",
Usage: "customize number concurrent files to process",
Value: 100,
EnvVar: "PLUGIN_MAX_CONCURRENCY",
},
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -145,6 +152,7 @@ func run(c *cli.Context) error {
Redirects: c.Generic("redirects").(*MapFlag).Get(), Redirects: c.Generic("redirects").(*MapFlag).Get(),
CloudFrontDistribution: c.String("cloudfront-distribution"), CloudFrontDistribution: c.String("cloudfront-distribution"),
DryRun: c.Bool("dry-run"), DryRun: c.Bool("dry-run"),
MaxConcurrency: c.Int("max-concurrency"),
} }
return plugin.Exec() return plugin.Exec()

View File

@ -28,10 +28,9 @@ type Plugin struct {
PathStyle bool PathStyle bool
client AWS client AWS
jobs []job jobs []job
MaxConcurrency int
} }
const maxConcurrent = 100
type job struct { type job struct {
local string local string
remote string remote string
@ -156,7 +155,7 @@ func (p *Plugin) createInvalidateJob() {
func (p *Plugin) runJobs() { func (p *Plugin) runJobs() {
client := p.client client := p.client
jobChan := make(chan struct{}, maxConcurrent) jobChan := make(chan struct{}, p.MaxConcurrency)
results := make(chan *result, len(p.jobs)) results := make(chan *result, len(p.jobs))
var invalidateJob *job var invalidateJob *job