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

Fix type of retry option: retry can be boolean or a number #49

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

Antti
Copy link
Contributor

@Antti Antti commented Sep 24, 2024

According to the sidekiq docs, sidekiq_options retry param can be either boolean or a number.

Change the param of the retry argument to be a JsonValue for now, as it's a convenient wrapper over different basic types

Leave it as a JsonValue for now for better compatibility
@film42
Copy link
Owner

film42 commented Sep 28, 2024

Thanks for the PR. Good find!

I think JsonValue is convenient but a little too broad. Let me see if I can push a change up that captures this intent though.

@film42
Copy link
Owner

film42 commented Sep 29, 2024

@Antti would you mind allowing maintainer push to your fork?

I refactored from JsonValue (which was a very helpful refresher so thank you for the PR) to a new RetryOpts type with a backwards compatible retry() method that now supports:

opts()
  // old way
  .retry(true).retry(false)
  // now usize is supported
  .retry(42)
  // and the new enum is available too
  .retry(RetryOpts::Yes).retry(RetryOpts::Never).retry(RetryOpts::Max(42)

I have a branch up here that I can open a new PR with but would love your thoughts: https://github.com/film42/sidekiq-rs/compare/gt/retry_opts?expand=1

I would like to add a few tests but I'm on a flight at the moment and I'll be out of internet range soon so wanted to get this up for the moment.

This changes JsonValue to RetryOpts which is an enum for Yes, Never, and
Max(n) to support the sidekiq bool|int typing. The public builder
interfaces for opts have now been moved to Into<RetryOpts> which will
continue to work for true/false like before but also a numeric value.

Also... I found that I hadn't impl'd the RetryMiddleware to respect a
retry: false option, so that's been fixed. I also added max_retries to
be plucked from the job if set and will be used in favor of whatever the
value was for the worker since they can be different.

TODO: Need to add a test for the new retry middleware logic. That
shouldn't have been a bug in the first place.
@Antti
Copy link
Contributor Author

Antti commented Oct 2, 2024

@film42 I think it looks good, certainly better than a plain JsonValue!

@film42
Copy link
Owner

film42 commented Oct 2, 2024

Sweet. I need to do a few more small things before cutting a new release.

@film42 film42 merged commit 40232a4 into film42:master Oct 2, 2024
1 check failed
@film42
Copy link
Owner

film42 commented Oct 2, 2024

Thanks for getting this one started, @Antti ! ❤️ ❤️ ❤️

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