MCPcopy
hub / github.com/robfig/cron / DelayIfStillRunning

Function DelayIfStillRunning

chain.go:61–74  ·  view source on GitHub ↗

DelayIfStillRunning serializes jobs, delaying subsequent runs until the previous one is complete. Jobs running after a delay of more than a minute have the delay logged at Info.

(logger Logger)

Source from the content-addressed store, hash-verified

59// previous one is complete. Jobs running after a delay of more than a minute
60// have the delay logged at Info.
61func DelayIfStillRunning(logger Logger) JobWrapper {
62 return func(j Job) Job {
63 var mu sync.Mutex
64 return FuncJob(func() {
65 start := time.Now()
66 mu.Lock()
67 defer mu.Unlock()
68 if dur := time.Since(start); dur > time.Minute {
69 logger.Info("delay", "duration", dur)
70 }
71 j.Run()
72 })
73 }
74}
75
76// SkipIfStillRunning skips an invocation of the Job if a previous invocation is
77// still running. It logs skips to the given logger at Info level.

Callers 1

Calls 3

FuncJobFuncType · 0.85
InfoMethod · 0.65
RunMethod · 0.65

Tested by 1