fix: Return from update loop when job completes (#1121)

Update was running forever, which stopped jobs from timing
out unless a restart occurred. This also fixes complete properly
reporting an error.
This commit is contained in:
Kyle Carberry
2022-04-25 03:41:03 +00:00
committed by GitHub
parent d44876382d
commit a6ea99541e
+6
View File
@@ -247,6 +247,9 @@ func (p *Server) acquireJob(ctx context.Context) {
func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
shutdown, shutdownCancel := context.WithCancel(ctx)
defer shutdownCancel()
complete, completeCancel := context.WithCancel(ctx)
defer completeCancel()
go func() {
ticker := time.NewTicker(p.opts.UpdateInterval)
defer ticker.Stop()
@@ -256,6 +259,8 @@ func (p *Server) runJob(ctx context.Context, job *proto.AcquiredJob) {
return
case <-ctx.Done():
return
case <-complete.Done():
return
case <-p.shutdown:
p.opts.Logger.Info(ctx, "attempting graceful cancelation")
shutdownCancel()
@@ -816,6 +821,7 @@ func (p *Server) completeJob(job *proto.CompletedJob) {
}
if err != nil {
p.opts.Logger.Warn(p.closeContext, "failed to complete job", slog.Error(err))
p.failActiveJobf(err.Error())
return
}
break