Skip to content

Commit

Permalink
Rename --concurrency to --concurrent-requests :trollface:
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Oct 1, 2017
1 parent 10b3c27 commit bceea0e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
36 changes: 18 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import (
)

type options struct {
DefaultRegistry string `short:"r" long:"default-registry" default:"registry.hub.docker.com" description:"Docker registry to use by default" env:"DEFAULT_REGISTRY"`
Username string `short:"u" long:"username" default:"" description:"Docker registry username" env:"USERNAME"`
Password string `short:"p" long:"password" default:"" description:"Docker registry password" env:"PASSWORD"`
DockerJSON string `shord:"j" long:"docker-json" default:"~/.docker/config.json" env:"DOCKER_JSON"`
Concurrency int `short:"c" long:"concurrency" default:"32" description:"Concurrent request limit while querying registry" env:"CONCURRENCY"`
Pull bool `short:"P" long:"pull" description:"Pull images matched by filter" env:"PULL"`
InsecureRegistry bool `short:"i" long:"insecure-registry" description:"Use insecure plain-HTTP registriy" env:"INSECURE_REGISTRY"`
TraceRequests bool `short:"T" long:"trace-requests" description:"Trace registry HTTP requests" env:"TRACE_REQUESTS"`
Version bool `short:"V" long:"version" description:"Show version and exit"`
Positional struct {
DefaultRegistry string `short:"r" long:"default-registry" default:"registry.hub.docker.com" description:"Docker registry to use by default" env:"DEFAULT_REGISTRY"`
Username string `short:"u" long:"username" default:"" description:"Docker registry username" env:"USERNAME"`
Password string `short:"p" long:"password" default:"" description:"Docker registry password" env:"PASSWORD"`
DockerJSON string `shord:"j" long:"docker-json" default:"~/.docker/config.json" env:"DOCKER_JSON"`
ConcurrentRequests int `short:"c" long:"concurrent-requests" default:"32" description:"Limit of concurrent requests to the registry" env:"CONCURRENT_REQUESTS"`
Pull bool `short:"P" long:"pull" description:"Pull images matched by filter" env:"PULL"`
InsecureRegistry bool `short:"i" long:"insecure-registry" description:"Use insecure plain-HTTP registriy" env:"INSECURE_REGISTRY"`
TraceRequests bool `short:"T" long:"trace-requests" description:"Trace registry HTTP requests" env:"TRACE_REQUESTS"`
Version bool `short:"V" long:"version" description:"Show version and exit"`
Positional struct {
Repositories []string `positional-arg-name:"REPO1 REPO2" description:"Docker repositories to operate on"`
} `positional-args:"yes"`
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func main() {

authorization := getAuthorization(tresp)

registryTags, err := registry.FetchTags(registryName, repoRegistryName, authorization, o.Concurrency)
registryTags, err := registry.FetchTags(registryName, repoRegistryName, authorization, o.ConcurrentRequests)
if err != nil {
suicide(err)
}
Expand Down Expand Up @@ -234,32 +234,32 @@ func main() {
}

if o.Pull {
quits := make(chan bool, repoCount)
done := make(chan bool, repoCount)

for _, tr := range tagResults {
go func(tags []*tag.Tag, repo string, quits chan bool) {
go func(tags []*tag.Tag, repo string, done chan bool) {
for _, tg := range tags {
if tg.NeedsPull() {
ref := repo + ":" + tg.GetName()

fmt.Printf("PULLING: %s\n", ref)
fmt.Printf("PULLING %s\n", ref)
err := local.Pull(ref)
if err != nil {
suicide(err)
}
}

quits <- true
done <- true
}
}(tr.Tags, tr.Repo, quits)
}(tr.Tags, tr.Repo, done)
}

repoNumber := 0
for range quits {
for range done {
repoNumber++

if repoNumber >= repoCount {
close(quits)
close(done)
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions tag/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ type detailResponse struct {
Error error
}

func validateConcurrency(concurrency int) (int, error) {
func validateConcurrentRequests(concurrentRequests int) (int, error) {
const min = 1
const max = 128

if concurrency < min {
return 0, errors.New("Concurrency could not be lower than " + strconv.Itoa(min))
if concurrentRequests < min {
return 0, errors.New("Concurrent requests limit could not be lower than " + strconv.Itoa(min))
}

if concurrency > max {
return 0, errors.New("Concurrency could not be higher than " + strconv.Itoa(max))
if concurrentRequests > max {
return 0, errors.New("Concurrent requests limit could not be higher than " + strconv.Itoa(max))
}

return concurrency, nil
return concurrentRequests, nil
}

func calculateBatchSteps(count, limit int) (int, int) {
Expand All @@ -263,8 +263,8 @@ func calculateBatchStepSize(stepNumber, stepsTotal, remain, limit int) int {
}

// FetchTags looks up Docker repo tags present on remote Docker registry
func FetchTags(registry, repo, authorization string, concurrency int) (map[string]*tag.Tag, error) {
batchLimit, err := validateConcurrency(concurrency)
func FetchTags(registry, repo, authorization string, concurrentRequests int) (map[string]*tag.Tag, error) {
batchLimit, err := validateConcurrentRequests(concurrentRequests)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit bceea0e

Please sign in to comment.