Declaration: mle86\Job\JobContext
Source file: src/WQ/Job/JobContext.php
Contains metadata about the job currently being processed and various setters to attach one-off event handlers to the job.
Instances of this class are available in job callbacks
run by WorkProcessor::processNextJob()
(their expected signature is function(Job, JobContext): ?int|void
).
(Only the WorkProcessor
class should create instances of this class.)
public function getQueueEntry(): QueueEntry
The queue entry DTO containing the current job instance.public function getJob(): Job
The job currently being executed.public function getSourceQueue(): string
The name of the work queue from which the current job was received.public function getWorkProcessor(): WorkProcessor
The WorkProcessor that created this instance.public function getWorkServer(): WorkServerAdapter
The work server from which the current job was received.
Additionally, it's possible to attach one or more callbacks to the current job context. One of them will be run when the job callback returns (or throws an exception).
This may be useful for job handlers
that want to perform cleanup
only in case of a permanently-failed job (onFailure
)
but not on a temporarily-failed job (onTemporaryFailure
)
Expected signature for the onSuccess callbacks:
function(Job, JobContext): void
.
Expected signature for the onFailure and onTemporaryFailure callbacks:
function(Job, JobContext, ?Throwable): void
.
-
public function onTemporaryFailure(?callable $callback): void
Sets up a callback that will be called once if and when the current job is being re-queued because it failed and should be re-tried.
This happens if WP_ENABLE_RETRY is set, if jobCanRetry() is true, and if the job handler returnedJobResult::FAILED
or threw aRuntimeException
. (Any such exception will be passed to the callback in its third argument.)
(This callback will be run by the WorkProcessor after it calls its internalonJobRequeue()
hook, immediately before callingWorkServerAdapter::requeueEntry()
.) -
public function onFailure(?callable $callback): void
Sets up a callback that will be called once if and when the current job is being buried/deleted because it failed and should not (or cannot) be re-tried later.
This happens if WP_ENABLE_RETRY is not set or if jobCanRetry() returns false and if the job handler returnedJobResult::ABORT
or threw a non-RuntimeException
throwable. (Any such exception will be passed to the callback in its third argument.)
(This callback will be run by the WorkProcessor after it calls its internalonFailedJob()
hook, immediately before callingWorkServerAdapter::buryEntry()
/deleteEntry()
.) -
public function onSuccess(?callable $callback): void
Sets up a callback that will be called once if and when the current job is being deleted/movied because it succeeded!
This happens if the job handler returnsJobResult::SUCCESS
/null
/void.
(This callback will be run by the WorkProcessor after it calls its internalonSuccessfulJob()
hook, immediately before callingWorkServerAdapter::deleteEntry()
/requeueEntry()
.)