Add option to allow ActiveJob
to manage retries on app-level first
#103
+117
−19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off: a big thank you to all contributors that made this Gem possible! 🚀
Motivation
Our company ran into some unfortunate circumstances regarding retries and failing jobs with an app that relies on Rails'
ActiveJob
and (depending on the tenant)Sidekiq
/Redis
orCloudtasker
/CloudTask
as the backend:due to the behavior already described in
some jobs were retried endlessly in the CloudTask-based stacks.
Proposed solution
My suggestion would be to let a config option
retry_mechanism
control whetherActiveJob
sexecutions
counter is overridden with the value of CloudTask'sRetryCounter
header.As implemented,
ActiveJob
should be able to handle retries usingretry_on
and only after those are used up let the backend handle further retries.Drawbacks of the proposed solution
config.max_retries
will be without effect in the implementation at hand ifActiveJob
is chosen, asexecutions
is not "handed back" to Cloudtasker to update onceActiveJob
is done retrying and bubbles errors up for the backend to handle.If it is acceptable to introduce a retry counter variable that does not clash with AJ's
executions
, e.g. like Sidekiq'sretry_count
, this could be a possible way out.The behavior of first handling retries on application level and then on backend/adapter level is probably quite unintuitive and must be documented to prevent people from accidentally shooting themselves in the foot.
a Rails-specific config variable is introduced that has no relevance for projects that do not even use the
CloudtaskerAdapter
Alternative
A more elaborate mechanism could provide the means to configure both app-level and backend-level retries at the same time. This would include either a "hand-off" of the execution/retry counters when the responsibility changes or separate means of tracking and applying executions/retries.
It would be great if you could consider including this change and/or sharing your thoughts on how this contribution can be improved.