feat: allow graceful shutdowns

Add a Shutdown(context.Context) method to the Poller. This will first
shutdown all active polling, preventing any new jobs from spawning. It
will then wait for either all jobs to finish, or for the context to
finish. If the context finishes, it will then force all jobs to end,
and then exit.
This commit is contained in:
Rowan Bohde
2024-04-25 13:53:18 -05:00
parent 1735b26e66
commit b350719527
2 changed files with 54 additions and 9 deletions

View File

@@ -122,9 +122,12 @@ func runDaemon(ctx context.Context, configFile *string) func(cmd *cobra.Command,
poller := poll.New(cfg, cli, runner)
poller.Poll(ctx)
go poller.Poll()
return nil
<-ctx.Done()
log.Infof("runner: %s gracefully shutting down", resp.Msg.Runner.Name)
return poller.Shutdown(context.Background())
}
}