Fix too long sleep

This commit is contained in:
Richard Patel 2019-02-03 16:28:43 +01:00
parent e919323169
commit ef7d17cad4
No known key found for this signature in database
GPG Key ID: C268B2BBDA2ABECB

11
main.go
View File

@ -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
}
}