Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 2.6 KB

Ref_Job_interface.md

File metadata and controls

64 lines (50 loc) · 2.6 KB

Job Interface

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.

Methods

  • 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 after jobRetryDelay() 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. If jobCanRetry() 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 return 1, on the first retry, this must return 2, and so on.

  • public function jobIsExpired (): bool
    Return true 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 return false here if your job class cannot expire.
    (Also see JobResult::EXPIRED which has the same effect as returning true 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