Constants

WORKER_SERVER

WORKER_SERVER ='server'

WORKER_CLIENT

WORKER_CLIENT ='client'

RECURRING_EXCEPTION_ITEMS

RECURRING_EXCEPTION_ITEMS =4

If x jobs of the same type fails, pause all other jobs to avoid unnecessary executions.

A UI dialog needs to be shown to the user so the user can decide to repeat or delete jobs.

RECURRING_EXCEPTION_CODE

RECURRING_EXCEPTION_CODE ='queue_paused_previous_failed'

Properties

$id

$id :integer

ID.

Type

integer

$type

$type :string

The type describes the unique type of this job. Something like `rpm-move-file` (with a prefix of your plugin).

Type

string

$worker

$worker :string

Where should this job be executed? Default is `server`. If you set this to `client` you need to manually resolve this job as done in your frontend coding (e.g. extra request).

Client-Worker:

  • You need to register your callable via JavaScript function: exposeCallable()
  • You need to manually expose a REST API call so you can update the job with passthruClientResult()
  • You can run into multiple executions for client-tasks, expect you do an explicit locked check before starting the expensive task
    • You can also avoid this, e.g. when you send the results of the client-worked task to the PHP client -> check if the job got already processed by another tab.

Please use WORKER_ constants.

Type

string

$group_uuid

$group_uuid :string

Do not use this manually! See `Persist::startGroup`.

Type

string

$group_position

$group_position :integer

The jobs' position within this group.

Type

integer

$group_total

$group_total :integer

Due to the fact we have a garbage collection of jobs in our database table, but we want to keep track of the total items within this group (e.g. Website scanner = Total sites to scan).

Type

integer

$process

$process :integer

Describe the process for this job. So you could iteratively work at this job within different executions.

Type

integer

$process_total

$process_total :integer

The total process needed of `process` to consider this job as `done`.

Type

integer

$duration_ms

$duration_ms :integer

The duration took to complete this task.

Type

integer

$created

$created :string

Created time as ISO string.

Type

string

$data

$data :mixed

A `json_encode`able object which gets persisted for this job which you can use in your executor.

Type

mixed

$runs

$runs :integer

Shows, how often this job has been run already. This is needed for `retries`. You do not have to fill this!

Type

integer

$retries

$retries :integer

How often should the job be retried when failure before stopping the complete queue and show an error message?

Type

integer

$delay_ms

$delay_ms :integer

How long should be waited until the next job can be passed to the executor?

Type

integer

$lock_until

$lock_until :integer

Timestamp at which this job can be picked again. This is not yet implemented but this mechanism should be used for the `client` worker.

Type

integer

$locked

$locked :boolean

Is this job currently processing?

Type

boolean

$callable

$callable :callable

The callable for this job.

Attention: If you are using a client-worker, you need to register a custom event, see also CLIENT_JOB_EVENT_PREFIX for more information!

Please note the following things:

  • This field is only needed for server worker
  • You are not allowed to use object instances; only static methods or functions!
  • The callable gets one parameter: Job $job
  • You need to $job->updateProcess() to mark the job as in progress or done!
  • Your callable can throw an Exception or return a WP_Error instance
  • Your callable should be save to be also executed by users with minimal capabilities

Type

callable

$exception

$exception :null|\WP_Error

Exception caused by this job. This automatically pauses the complete queue.

Type

null|\WP_Error

$core

$core :

Type

$updatedJobsToAvoidRecurringException

$updatedJobsToAvoidRecurringException :boolean

Indicates, when run this job a recurring got detected and jobs got paused automatically.

Type

boolean

Methods

getPluginConstantPrefix()

getPluginConstantPrefix(): string

Get the prefix of this package so we can utils package natively.

Returns

string

setupConstants()

setupConstants()

Make sure the REAL_QUEUE constants are available.

isDone()

isDone()

Check if the job is already done?

isLastInGroup()

isLastInGroup()

Check if this job is the last in this group?

passthruClientResult()

passthruClientResult(integer|true  $process,\WP_Error|null  $error)

Save the state of the client worker result.

Parameters

integer|true $process
\WP_Error|null $error

updateProcess()

updateProcess(integer|true  $process)

Update `process` and mark the job as in progress or done.

Parameters

integer|true $process

updatedLocked()

updatedLocked(boolean  $locked)

Update `locked` attribute so jobs are not executed twice.

Parameters

boolean $locked

updateException()

updateException(\WP_Error|null  $error)

Update `exception` and mark the job as failed. This causes the complete queue to be paused.

Parameters

\WP_Error|null $error

execute()

execute(): void|\WP_Error

Execute this job on our server.

Returns

void|\WP_Error

omitClientData()

omitClientData()

Omit client data e.g. `data` of server-worker and `callable`.

hasUpdatedJobsToAvoidRecurringException()

hasUpdatedJobsToAvoidRecurringException()

Getter.

set_error_handler()

set_error_handler(string  $errno,string  $errstr,string  $errfile,integer  $errline,string  $errcontext = array())

Set error handler.

Parameters

string $errno
string $errstr
string $errfile
integer $errline
string $errcontext

Throws

\ErrorException

label()

label(string  $type)

See filter `DevOwl/RealQueue/Job/Label`.

Parameters

string $type

actions()

actions(string  $type)

See filter `DevOwl/RealQueue/Job/Actions`.

Parameters

string $type

updateRuns()

updateRuns(integer  $previousProcess,integer  $force = null)

Update `runs` so `retries` works as expected.

Parameters

integer $previousProcess
integer $force

cumulateDuration()

cumulateDuration(integer|float  $start)

Update `duration`.

Parameters

integer|float $start

microtime(true) before you do something heavy

avoidRecurringException()

avoidRecurringException()

When a job fails, check if jobs from the same type failed a few times before, too.

If yes, update runs and set an exception that signals a paused queue.