Introduce PayloadNotFoundError (subclass of DeserializationError) #1004
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.
Currently, there are two types of
DeserializationError
s:The handler code itself is malformed, e.g. triggered by a
Psych::SyntaxError
The payload object is not found in the database (refer to
Delayed::PsychExt
class, e.g. the below)Case 1 makes sense to handle by immediately permanently failing the job, if the yaml is malformed the job will never run.
Case 2 however, there is a possibility that the job will run at a later time, as the object could appear later in the database. This is especially true for Mongoid, which is non-transactional and uses replication with some minor timelag. When triggering a delayed job (e.g. a mailer) on new object creation, the job can possibly be invoked and query a replica set member BEFORE the data has replicated, raising a Mongoid::Errors::DocumentNotFound which is re-raised as a Delayed::DeserializationError.
To give power users like myself more flexibility, I've introduced a new config
Delayed::Worker.fail_if_payload_not_found
. The default is the current behavior (immediate failure) however it can be tweaked to retry.