From ef7d17cad47e5293cb372b2c6da2491ffcb93c11 Mon Sep 17 00:00:00 2001 From: Richard Patel Date: Sun, 3 Feb 2019 16:28:43 +0100 Subject: [PATCH] Fix too long sleep --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1259408..d20b696 100644 --- a/main.go +++ b/main.go @@ -97,7 +97,7 @@ func cmdBase(_ *cobra.Command, _ []string) { if err != nil { logrus.WithError(err). Error("Failed to get new task") - time.Sleep(viper.GetDuration(ConfCooldown)) + sleep(viper.GetDuration(ConfCooldown), appCtx) continue } if t == nil { @@ -189,3 +189,12 @@ func hardShutdown(c context.Context) { <-c.Done() os.Exit(1) } + +func sleep(d time.Duration, c context.Context) { + select { + case <-time.After(d): + break + case <-c.Done(): + break + } +}