mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user