MCPcopy
hub / github.com/pocketbase/pocketbase / Start

Method Start

tools/cron/cron.go:178–208  ·  view source on GitHub ↗

Start starts the cron ticker. Calling Start() on already started cron will restart the ticker.

()

Source from the content-addressed store, hash-verified

176//
177// Calling Start() on already started cron will restart the ticker.
178func (c *Cron) Start() {
179 c.Stop()
180
181 // delay the ticker to start at 00 of 1 c.interval duration
182 now := time.Now()
183 next := now.Add(c.interval).Truncate(c.interval)
184 delay := next.Sub(now)
185
186 c.mux.Lock()
187 c.startTimer = time.AfterFunc(delay, func() {
188 c.mux.Lock()
189 c.ticker = time.NewTicker(c.interval)
190 c.mux.Unlock()
191
192 // run immediately at 00
193 c.runDue(time.Now())
194
195 // run after each tick
196 go func() {
197 for {
198 select {
199 case <-c.tickerDone:
200 return
201 case t := <-c.ticker.C:
202 c.runDue(t)
203 }
204 }
205 }()
206 })
207 c.mux.Unlock()
208}
209
210// HasStarted checks whether the current Cron ticker has been started.
211func (c *Cron) HasStarted() bool {

Callers 5

SetIntervalMethod · 0.95
LaunchURLFunction · 0.45
TestCronStartStopFunction · 0.45
registerBaseHooksMethod · 0.45
mainFunction · 0.45

Calls 4

StopMethod · 0.95
runDueMethod · 0.95
SubMethod · 0.80
AddMethod · 0.45

Tested by 1

TestCronStartStopFunction · 0.36