MCPcopy Index your code
hub / github.com/coder/coder / StartCron

Method StartCron

agent/agentscripts/agentscripts.go:166–187  ·  view source on GitHub ↗

StartCron starts the cron scheduler. This is done async to allow for the caller to execute scripts prior.

()

Source from the content-addressed store, hash-verified

164// StartCron starts the cron scheduler.
165// This is done async to allow for the caller to execute scripts prior.
166func (r *Runner) StartCron() {
167 // cron.Start() and cron.Stop() does not guarantee that the cron goroutine
168 // has exited by the time the `cron.Stop()` context returns, so we need to
169 // track it manually.
170 err := r.trackCommandGoroutine(func() {
171 // Since this is run async, in quick unit tests, it is possible the
172 // Close() function gets called before we even start the cron.
173 // In these cases, the Run() will never end.
174 // So if we are closed, we just return, and skip the Run() entirely.
175 select {
176 case <-r.cronCtx.Done():
177 // The cronCtx is canceled before cron.Close() happens. So if the ctx is
178 // canceled, then Close() will be called, or it is about to be called.
179 // So do nothing!
180 default:
181 r.cron.Run()
182 }
183 })
184 if err != nil {
185 r.Logger.Warn(context.Background(), "start cron failed", slog.Error(err))
186 }
187}
188
189// ExecuteOption describes what scripts we want to execute.
190type ExecuteOption int

Callers 2

handleManifestMethod · 0.80
TestCronCloseFunction · 0.80

Calls 4

trackCommandGoroutineMethod · 0.95
RunMethod · 0.65
DoneMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestCronCloseFunction · 0.64