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 max_retries Method #31

Merged
merged 3 commits into from
Sep 5, 2024
Merged

Conversation

orioldsm
Copy link
Contributor

@orioldsm orioldsm commented Sep 5, 2024

Currently max_retries is not properly calculating a value of 0 when the retry value is set to false. This change fixes the max_retries method to accurately determine the max retry count in all cases. It also adds thorough testing to cover these cases.

@@ -13,10 +13,17 @@ def worker_dog_options(worker)
end

def max_retries(worker)
retries = worker.class.get_sidekiq_options['retry'] || Sidekiq[:max_retries]
Copy link
Contributor Author

@orioldsm orioldsm Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing the worker to always default to the global Sidekiq[:max_retries] value even ifworker.class.get_sidekiq_options['retry'] was set to false, which is NOT the intended behavior.

Comment on lines 17 to 26
case retries.to_s
when "true"
Sidekiq[:max_retries]
when "false"
0
when ""
Sidekiq[:max_retries]
else
retries
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider

Suggested change
case retries.to_s
when "true"
Sidekiq[:max_retries]
when "false"
0
when ""
Sidekiq[:max_retries]
else
retries
end
case retries.to_s
when "true", ""
Sidekiq[:max_retries]
when "false"
0
else
retries
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, honestly, we should not be passing in boolean values at all, Sidekiq is clearly written with numbers in mind (and just doesn't validate that)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh neat, I didn't know that syntax was allowed in Ruby - good shout thanks.

I agree that it's unfortunate we have to handle so many cases because there doesn't really seem to be a good standardized way we're doing it :(

Copy link
Contributor

@kaisensan kaisensan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec/sidekiq-instrument/server_middleware_spec.rb Outdated Show resolved Hide resolved
spec/sidekiq-instrument/server_middleware_spec.rb Outdated Show resolved Hide resolved
spec/sidekiq-instrument/server_middleware_spec.rb Outdated Show resolved Hide resolved
spec/sidekiq-instrument/server_middleware_spec.rb Outdated Show resolved Hide resolved
spec/sidekiq-instrument/server_middleware_spec.rb Outdated Show resolved Hide resolved
@kaisensan kaisensan merged commit 0ef322c into enova:main Sep 5, 2024
13 checks passed
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.

3 participants