Handle no run when rescuing errors in TaskJob #375
Merged
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.
Closes: #374
Errors in a Task can occur before the
before_perform
callback runs (ie. before@run
) is set. The main scenario to be concerned about here is if deserializing the run fails (in the Partners app, this happened because the connection to the MySQL server was lost when attempting to deserialize). Another case to consider is that users might have a custom Job with a callback that raises for some reason, prior to ourTaskJob#before_perform
callback happening.Right now,
on_error
blows up when@run
is not defined. This leads to unintended consequences - namely, job retries happening that we are not in control of. The upside is that it makes the framework somewhat "resilient" (ie. the job might retry and succeed, leading the Task to continue running successfully), but this actually ends up being problematic because we can't determine exactly what will happen, and it might lead to therun
getting into a state that messes up the whole system.We should solve this by only calling methods on
@run
if it's defined. Otherwise, we can still call the error handler, but do so with an emptytask_context
hash.I thought about checking
if defined?(@run) && @run
, but I'm pretty sure@run
has to be present if it's defined since we control enqueuingTaskJob
in theRunner
. (So either we fail to deserialize properly and that blows up, or we set@run
to a valid object. Since we're the only ones who enqueue this job viaRunner#enqueue
, I don't think this could ever get set to nil, it can only be undefined)