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

Function Recover

chain.go:38–56  ·  view source on GitHub ↗

Recover panics in wrapped jobs and log them with the provided logger.

(logger Logger)

Source from the content-addressed store, hash-verified

36
37// Recover panics in wrapped jobs and log them with the provided logger.
38func Recover(logger Logger) JobWrapper {
39 return func(j Job) Job {
40 return FuncJob(func() {
41 defer func() {
42 if r := recover(); r != nil {
43 const size = 64 << 10
44 buf := make([]byte, size)
45 buf = buf[:runtime.Stack(buf, false)]
46 err, ok := r.(error)
47 if !ok {
48 err = fmt.Errorf("%v", r)
49 }
50 logger.Error(err, "panic", "stack", "...\n"+string(buf))
51 }
52 }()
53 j.Run()
54 })
55 }
56}
57
58// DelayIfStillRunning serializes jobs, delaying subsequent runs until the
59// previous one is complete. Jobs running after a delay of more than a minute

Callers 3

TestChainRecoverFunction · 0.85
TestFuncPanicRecoveryFunction · 0.85
TestJobPanicRecoveryFunction · 0.85

Calls 3

FuncJobFuncType · 0.85
ErrorMethod · 0.65
RunMethod · 0.65

Tested by 3

TestChainRecoverFunction · 0.68
TestFuncPanicRecoveryFunction · 0.68
TestJobPanicRecoveryFunction · 0.68