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)
| 58 | // until it returns. Return the backoff duration after which another single run |
| 59 | // should be performed. |
| 60 | func (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 | } |
no test coverage detected