From c2ec2adc503cbd86d82233a763550aeb0c376316 Mon Sep 17 00:00:00 2001 From: Ivan Pesin Date: Sun, 10 Sep 2017 22:49:48 -0500 Subject: [PATCH] Update hookExecutions limits on configuration reload --- webhook.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/webhook.go b/webhook.go index 8cb5f0b..18fafdc 100644 --- a/webhook.go +++ b/webhook.go @@ -403,7 +403,27 @@ func reloadHooks(hooksFilePath string) { } seenHooksIds[hook.ID] = true - log.Printf("\tloaded: %s\n", hook.ID) + msg := fmt.Sprintf("\tloaded: %s", hook.ID) + + // initialize or update concurrency map + switch { + case hook.MaxConcurrency == 0: + if _, ok := hookExecutions[hook.ID]; ok { + delete(hookExecutions, hook.ID) + } + msg = fmt.Sprintf("%s", msg) + case hook.MaxConcurrency > 0: + hookExecutions[hook.ID] = make(chan struct{}, hook.MaxConcurrency) + msg = fmt.Sprintf("%s (max: %d)", msg, hook.MaxConcurrency) + } + log.Println(msg) + } + + // clean up hookExecutions channels for removed hooks + for _, loadedHook := range loadedHooksFromFiles[hooksFilePath] { + if _, ok := seenHooksIds[loadedHook.ID]; !ok { + delete(hookExecutions, loadedHook.ID) + } } loadedHooksFromFiles[hooksFilePath] = hooksInFile @@ -418,6 +438,9 @@ func reloadAllHooks() { func removeHooks(hooksFilePath string) { for _, hook := range loadedHooksFromFiles[hooksFilePath] { log.Printf("\tremoving: %s\n", hook.ID) + if _, ok := hookExecutions[hook.ID]; ok { + delete(hookExecutions, hook.ID) + } } newHooksFiles := hooksFiles[:0]