From baad906d24743ea8f550bd2434c491278f613d92 Mon Sep 17 00:00:00 2001 From: Ivan Pesin Date: Sun, 10 Sep 2017 21:36:17 -0500 Subject: [PATCH] Corrected parameter name, typo, error message, and variable naming --- hook/hook.go | 2 +- webhook.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/hook/hook.go b/hook/hook.go index a271630..8689f97 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -381,7 +381,7 @@ type Hook struct { PassEnvironmentToCommand []Argument `json:"pass-environment-to-command,omitempty"` PassArgumentsToCommand []Argument `json:"pass-arguments-to-command,omitempty"` JSONStringParameters []Argument `json:"parse-parameters-as-json,omitempty"` - MaxConcurrency int `json:"max-concurrency,omiempty"` + MaxConcurrency int `json:"maximum-concurrent-executions,omitempty"` TriggerRule *Rules `json:"trigger-rule,omitempty"` TriggerRuleMismatchHttpResponseCode int `json:"trigger-rule-mismatch-http-response-code,omitempty"` } diff --git a/webhook.go b/webhook.go index 05989da..8982aa1 100644 --- a/webhook.go +++ b/webhook.go @@ -44,7 +44,7 @@ var ( watcher *fsnotify.Watcher signals chan os.Signal - limits = make(map[string]chan struct{}) + hookExecutions = make(map[string]chan struct{}) ) func matchLoadedHook(id string) *hook.Hook { @@ -115,7 +115,7 @@ func main() { // initialize concurrency map if hook.MaxConcurrency > 0 { - limits[hook.ID] = make(chan struct{}, hook.MaxConcurrency) + hookExecutions[hook.ID] = make(chan struct{}, hook.MaxConcurrency) msg = fmt.Sprintf("%s (max: %d)", msg, hook.MaxConcurrency) } log.Println(msg) @@ -219,15 +219,15 @@ func hookHandler(w http.ResponseWriter, r *http.Request) { log.Printf("%s got matched\n", id) // check if we have concurrency limits - if _, ok := limits[id]; ok { - if len(limits[id]) == cap(limits[id]) { - log.Printf("reached concurrency limit for: %s (max=%d)", id, len(limits[id])) + if _, ok := hookExecutions[id]; ok { + if len(hookExecutions[id]) == cap(hookExecutions[id]) { + log.Printf("reached concurrency limit for: %s (max=%d)", id, len(hookExecutions[id])) w.WriteHeader(http.StatusTooManyRequests) - fmt.Fprintf(w, "Error occurred while evaluating hook rules.") + fmt.Fprintf(w, "Hook reached maximum concurrent execution limit. Try again later.") return } - defer func() { <-limits[id] }() - limits[id] <- struct{}{} + defer func() { <-hookExecutions[id] }() + hookExecutions[id] <- struct{}{} } body, err := ioutil.ReadAll(r.Body)