Declaration: abstract class mle86\WQ\Job\AbstractJob implements Job
Source file: src/WQ/Job/AbstractJob.php
To build a working Job class, simply extend this class.
- It's your choice whether to put your job execution logic in the Job class or somewhere else entirely, like the queue worker script.
- If the jobs should be re-tried after an initial failure,
override the
MAX_RETRY
constant. - If the retry condition is more complex,
override the
jobCanRetry()
method instead. - To change the retry delay interval,
override the
jobRetryDelay()
method (you'll probably want to have an increasing delay, so base it on thejobTryIndex()
counter value). - If your queued jobs can expire before being executed,
override
jobIsExpired()
so that it returnstrue
if the expiry condition is reached. You may need to add a job creation timestamp property for that.
It fully implements the Job
interface.
public function jobRetryDelay (): ?int { … }
SeeJob::jobRetryDelay()
. This default implementation always returns 10 minutes.
public function jobTryIndex (): int { … }
SeeJob::jobTryIndex()
. This default implementation always returns the$_try_index
value or1
, whichever is greater.
public function serialize () { … }
This default implementation stores all public and protected properties. Override this method if that's not enough or if you want to do some additional pre-serialization processing, but don't forget to include$_try_index + 1
in the serialization!
public function unserialize (string $serialized) { … }
This default implementation simply writes all serialized values to their corresponding object property. That includes the$_try_index
counter. Private and/or static properties will never be written to.
public function jobCanRetry (): bool { … }
SeeJob::jobCanRetry()
. This default implementation always returnstrue
ifjobTryIndex() ≤ MAX_RETRY
.
public function jobIsExpired (): bool { … }
SeeJob::jobIsExpired()
. This default implementation always returnsfalse
, meaning thatAbstractJob
implementations never expire by default.
const int MAX_RETRY = 0
How often a job of this type can be retried if it fails. Override this as necessary in subclasses. Zero or negative values mean that this job can only be tried once, never re-tried.
(This is used in thejobCanRetry()
default implementation only, so if you override that method in your Job class the constant is unused.)
protected $_try_index = 0
The current try index.
The default__serialize()
implementation will increase this by 1 before serializing it, so that the serialization always contains the correct next value.
Internal: This should not be accessed directly, except for a custom__serialize()
override.