MCPcopy Create free account
hub / github.com/pace/bricks / singleRun

Method singleRun

pkg/routine/instance.go:60–85  ·  view source on GitHub ↗

Performs a single run. That is, to try to obtain the lock and run the routine until it returns. Return the backoff duration after which another single run should be performed.

(ctx context.Context)

Source from the content-addressed store, hash-verified

58// until it returns. Return the backoff duration after which another single run
59// should be performed.
60func (r *routineThatKeepsRunningOneInstance) singleRun(ctx context.Context) time.Duration {
61 l := redis.NewLock("routine:lock:"+r.Name, redis.SetTTL(r.lockTTL))
62 lockCtx, cancel, err := l.AcquireAndKeepUp(ctx)
63 if err != nil {
64 go errors.Handle(ctx, err) // report error to Sentry, non-blocking
65 return r.backoff.Duration("lock")
66 }
67 if lockCtx != nil {
68 defer cancel()
69 routinePanicked := true
70 func() {
71 defer errors.HandleWithCtx(ctx, fmt.Sprintf("routine %d", r.num)) // handle panics
72
73 span := sentry.StartSpan(lockCtx, "function", sentry.WithDescription(fmt.Sprintf("routine %d", r.num)))
74 defer span.Finish()
75
76 r.Routine(span.Context())
77 routinePanicked = false
78 }()
79 if routinePanicked {
80 return r.backoff.Duration("routine")
81 }
82 }
83 r.backoff.ResetAll()
84 return r.retryInterval
85}

Callers 1

RunMethod · 0.95

Calls 9

AcquireAndKeepUpMethod · 0.95
NewLockFunction · 0.92
SetTTLFunction · 0.92
HandleFunction · 0.92
HandleWithCtxFunction · 0.92
DurationMethod · 0.80
FinishMethod · 0.80
ContextMethod · 0.80
ResetAllMethod · 0.80

Tested by

no test coverage detected