Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate retries based off current time, not job start time #74

Merged
merged 1 commit into from
Nov 26, 2023

Conversation

bgentry
Copy link
Contributor

@bgentry bgentry commented Nov 26, 2023

In a demo app, I was seeing a bunch of errors with this message:

Retry policy returned invalid next retry before current time; using default retry policy instead

The only problem is, I was using the default retry policy for this worker and client. These log lines manifested because the DefaultClientRetryPolicy is calculating the next attempt based on:

job.AttemptedAt + backoffDuration

This isn't really noticeable if the job is super quick, but if like my demo app your job is taking 10s of seconds or longer, the next attempt could actually be scheduled for far in the past instead of in the future, making it run again immediately instead of after the backoff duration.

This commit changes the behavior to only look at the current time (time.Now().UTC()) when determining when the next attempt should be, without regard to when the last attempt began.

In a demo app, I was seeing a bunch of errors with this message:

> Retry policy returned invalid next retry before current time; using
> default retry policy instead

The only problem is, I _was_ using the default retry policy for this
worker and client. These log lines manifested because the
`DefaultClientRetryPolicy` is calculating the next attempt based on:

    job.AttemptedAt + backoffDuration

This isn't really noticeable if the job is super quick, but if like my
demo app your job is taking 10s of seconds or longer, the next attempt
could actually be scheduled for far in the past instead of in the
future, making it run again immediately instead of after the backoff
duration.

This commit changes the behavior to only look at the current time
(`time.Now().UTC()`) when determining when the next attempt should be,
without regard to when the last attempt began.
@bgentry bgentry requested a review from brandur November 26, 2023 21:32
@bgentry bgentry merged commit a6171e4 into master Nov 26, 2023
7 checks passed
@bgentry bgentry deleted the bg-fix-retry-policy branch November 26, 2023 22:24
bgentry added a commit that referenced this pull request Nov 27, 2023
This was changed in #74, but the changelog entry was added to an
existing version instead of the new/unreleased one.
bgentry added a commit that referenced this pull request Nov 27, 2023
This was changed in #74, but the changelog entry was added to an
existing version instead of the new/unreleased one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants