This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
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.
The
ping()
method can be useful for setting up recurring jobs if wedeliberately avoid acking the job. For example:
ping()
A real-world example of this might be notifying for recurring
appointments, or setting up long-running, cross-process, periodic jobs.
The main advantage this has over using
ack()
andadd()
is that iteffectively requeues a job in a single, atomic commit. If we tried the
above with
ack()
andadd()
:ack()
add()
In this version, the process could crash or quit between Steps 4 & 5,
and our recurring job would be lost.
We could also try inverting Steps 4 & 5, but then we get the opposite
issue: if the process crashes or quits, then we might accidentally
duplicate our recurring job. It also prevents us from setting up any
unique indexes on our
payload
.Using
ping()
perfectly solves this problem: there's only ever oneversion of the job, and it's never dropped (because it's never acked).
If the process crashes before we
ping()
, we'll retry it, as with anyother normal job.
The one issue with this approach is that
tries
will steadily increase,and - if you have
maxRetries
set up - the job will eventually be movedto the dead queue, which isn't what we want.
This change adds an option to the
ping()
method:resetTries
, whichwill reset
tries
to zero, so that the job is treated like a "new" jobwhen it's pinged, and is only moved to the dead queue if it's genuinely
retried.