Documentation

Job
in package
Uses UtilsProvider

A job model.

Table of Contents

Constants

RECURRING_EXCEPTION_CODE  = 'queue_paused_previous_failed'
RECURRING_EXCEPTION_ITEMS  = 4
If x jobs of the same type fails, pause all other jobs to avoid unnecessary executions.
WORKER_CLIENT  = 'client'
WORKER_SERVER  = 'server'

Properties

$callable  : callable
The callable for this job.
$created  : string
Created time as ISO string.
$data  : mixed
A `json_encode`able object which gets persisted for this job which you can use in your executor.
$delay_ms  : int
How long should be waited until the next job can be passed to the executor?
$duration_ms  : int
The duration took to complete this task.
$exception  : null|WP_Error
Exception caused by this job. This automatically pauses the complete queue.
$group_position  : int
The jobs' position within this group.
$group_total  : int
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).
$group_uuid  : string
Do not use this manually! See `Persist::startGroup`.
$id  : int
ID.
$lock_until  : int
Timestamp at which this job can be picked again. This is not yet implemented but this mechanism should be used for the `client` worker.
$locked  : bool
Is this job currently processing?
$process  : int
Describe the process for this job. So you could iteratively work at this job within different executions.
$process_total  : int
The total process needed of `process` to consider this job as `done`.
$retries  : int
How often should the job be retried when failure before stopping the complete queue and show an error message?
$runs  : int
Shows, how often this job has been run already. This is needed for `retries`. You do not have to fill this!
$type  : string
The type describes the unique type of this job. Something like `rpm-move-file` (with a prefix of your plugin).
$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).
$core  : mixed
$updatedJobsToAvoidRecurringException  : bool
Indicates, when run this job a recurring got detected and jobs got paused automatically.

Methods

__construct()  : mixed
C'tor.
actions()  : mixed
See filter `DevOwl/RealQueue/Job/Actions`.
execute()  : void|WP_Error
Execute this job on our server.
getPluginConstantPrefix()  : string
Get the prefix of this package so we can utils package natively.
hasUpdatedJobsToAvoidRecurringException()  : mixed
Getter.
isDone()  : mixed
Check if the job is already done?
isLastInGroup()  : mixed
Check if this job is the last in this group?
label()  : mixed
See filter `DevOwl/RealQueue/Job/Label`.
omitClientData()  : mixed
Omit client data e.g. `data` of server-worker and `callable`.
passthruClientResult()  : mixed
Save the state of the client worker result.
set_error_handler()  : mixed
Set error handler.
setupConstants()  : mixed
Make sure the REAL_QUEUE constants are available.
updatedLocked()  : mixed
Update `locked` attribute so jobs are not executed twice.
updateException()  : mixed
Update `exception` and mark the job as failed. This causes the complete queue to be paused.
updateProcess()  : mixed
Update `process` and mark the job as in progress or done.
avoidRecurringException()  : mixed
When a job fails, check if jobs from the same type failed a few times before, too.
cumulateDuration()  : mixed
Update `duration`.
updateRuns()  : mixed
Update `runs` so `retries` works as expected.

Constants

RECURRING_EXCEPTION_CODE

public mixed RECURRING_EXCEPTION_CODE = 'queue_paused_previous_failed'

RECURRING_EXCEPTION_ITEMS

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

public mixed RECURRING_EXCEPTION_ITEMS = 4

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

WORKER_CLIENT

public mixed WORKER_CLIENT = 'client'

WORKER_SERVER

public mixed WORKER_SERVER = 'server'

Properties

$callable

The callable for this job.

public callable $callable

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

$created

Created time as ISO string.

public string $created

$data

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

public mixed $data

$delay_ms

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

public int $delay_ms = 1000

$duration_ms

The duration took to complete this task.

public int $duration_ms

$exception

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

public null|WP_Error $exception

$group_position

The jobs' position within this group.

public int $group_position

$group_total

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).

public int $group_total

$group_uuid

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

public string $group_uuid

$id

ID.

public int $id

$lock_until

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

public int $lock_until

$locked

Is this job currently processing?

public bool $locked

$process

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

public int $process = 0

$process_total

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

public int $process_total = 1

$retries

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

public int $retries = 0

$runs

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

public int $runs = 0

$type

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

public string $type

$worker

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).

public string $worker = self::WORKER_SERVER

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.

$core

private mixed $core

$updatedJobsToAvoidRecurringException

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

private bool $updatedJobsToAvoidRecurringException = false

Methods

__construct()

C'tor.

public __construct(Core $core) : mixed
Parameters
$core : Core

actions()

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

public static actions(string $type) : mixed
Parameters
$type : string

execute()

Execute this job on our server.

public execute() : void|WP_Error
Return values
void|WP_Error

getPluginConstantPrefix()

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

public getPluginConstantPrefix() : string
Return values
string

hasUpdatedJobsToAvoidRecurringException()

Getter.

public hasUpdatedJobsToAvoidRecurringException() : mixed

isDone()

Check if the job is already done?

public isDone() : mixed

isLastInGroup()

Check if this job is the last in this group?

public isLastInGroup() : mixed

label()

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

public static label(string $type) : mixed
Parameters
$type : string

omitClientData()

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

public omitClientData() : mixed

passthruClientResult()

Save the state of the client worker result.

public passthruClientResult(int|true $process, WP_Error|null $error) : mixed
Parameters
$process : int|true
$error : WP_Error|null

set_error_handler()

Set error handler.

public static set_error_handler(string $errno, string $errstr, string $errfile, int $errline[, string $errcontext = [] ]) : mixed
Parameters
$errno : string
$errstr : string
$errfile : string
$errline : int
$errcontext : string = []
Tags
see
https://stackoverflow.com/a/1241751/5506547
throws
ErrorException

setupConstants()

Make sure the REAL_QUEUE constants are available.

public static setupConstants() : mixed

updatedLocked()

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

public updatedLocked(bool $locked) : mixed
Parameters
$locked : bool

updateException()

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

public updateException(WP_Error|null $error) : mixed
Parameters
$error : WP_Error|null

updateProcess()

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

public updateProcess(int|true $process) : mixed
Parameters
$process : int|true

avoidRecurringException()

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

protected avoidRecurringException() : mixed

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

cumulateDuration()

Update `duration`.

protected cumulateDuration(int|float $start) : mixed
Parameters
$start : int|float

microtime(true) before you do something heavy

updateRuns()

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

protected updateRuns(int $previousProcess[, int $force = null ]) : mixed
Parameters
$previousProcess : int
$force : int = null

        
On this page

Search results