mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(agent/agentscripts): track cron run and wait for cron stop (#10388)
Fixes #10289
This commit is contained in:
@@ -97,7 +97,15 @@ func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript) error {
|
|||||||
// StartCron starts the cron scheduler.
|
// StartCron starts the cron scheduler.
|
||||||
// This is done async to allow for the caller to execute scripts prior.
|
// This is done async to allow for the caller to execute scripts prior.
|
||||||
func (r *Runner) StartCron() {
|
func (r *Runner) StartCron() {
|
||||||
r.cron.Start()
|
// cron.Start() and cron.Stop() does not guarantee that the cron goroutine
|
||||||
|
// has exited by the time the `cron.Stop()` context returns, so we need to
|
||||||
|
// track it manually.
|
||||||
|
err := r.trackCommandGoroutine(func() {
|
||||||
|
r.cron.Run()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
r.Logger.Warn(context.Background(), "start cron failed", slog.Error(err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute runs a set of scripts according to a filter.
|
// Execute runs a set of scripts according to a filter.
|
||||||
@@ -254,7 +262,7 @@ func (r *Runner) Close() error {
|
|||||||
}
|
}
|
||||||
close(r.closed)
|
close(r.closed)
|
||||||
r.cronCtxCancel()
|
r.cronCtxCancel()
|
||||||
r.cron.Stop()
|
<-r.cron.Stop().Done()
|
||||||
r.cmdCloseWait.Wait()
|
r.cmdCloseWait.Wait()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user