Declaration: interface mle86\WQ\Job\Job
Source file: src/WQ/Job/Job.php
A Job is a representation of some task to do.
It can be stored in a Work Queue with WorkServerAdapter::storeJob()
.
All Jobs have to be serializable in order to be stored in a Work Queue.
For your own Job classes,
see the AbstractJob
base class instead;
it is easier to work with
as it provides default implementations
for the required methods,
including __serialize
and __unserialize
.
This interface does not specify how a Job should be executed or how the responsible method(s) should be named, if they are part of the Job implementation at all.
public function jobCanRetry (): bool
Whether this job can be retried later. The WorkProcessor helper class will check this if job execution has failed.
If it returns true, the job will be stored in the Work Queue again to be re-executed afterjobRetryDelay()
seconds; if it returns false, the job will be buried for later inspection.
public function jobRetryDelay (): ?int
How many seconds the job should be delayed in the Work Queue before being re-tried. IfjobCanRetry()
is true, this must return a positive integer (or zero, if the job should be re-tried as soon as possible).
public function jobTryIndex (): int
On the first try, this must return1
, on the first retry, this must return2
, and so on.
-
public function jobIsExpired (): bool
Returntrue
here if the instance should be considered expired. The WorkServerAdapter implementations will still return expired instances, but the WorkProcessor class won't process them – they will be deleted as soon as they are encountered. Always returnfalse
here if your job class cannot expire.
(Also seeJobResult::EXPIRED
which has the same effect as returningtrue
here.) -
public function __serialize (): array
,
public function __unserialize (array $data): void
Needed for serializability -- see https://www.php.net/manual/en/language.oop5.magic.php#object.unserialize