CRM_Queue_Queue
in package
A queue is an object (usually backed by some persistent data store) which stores a list of tasks or messages for use by other processes.
This would ideally be an interface, but it's handy to specify the "function __construct()" and the "$name" handling
Note: This interface closely parallels the DrupalQueueInterface.
Table of Contents
Constants
- DEFAULT_LEASE_TIME = 3600
Properties
- $queueSpec : array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
- $_name : string
Methods
- __construct() : mixed
- Create a reference to queue. After constructing the queue, one should usually call createQueue (if it's a new queue) or loadQueue (if it's known to be an existing queue).
- claimItem() : object
- Get the next item.
- createItem() : mixed
- Add a new item to the queue.
- createQueue() : mixed
- Perform any registration or resource-allocation for a new queue
- deleteItem() : mixed
- Remove an item from the queue.
- deleteQueue() : mixed
- Release any resources claimed by the queue (memory, DB rows, etc)
- existsQueue() : bool
- Check if the queue exists.
- fetchItem() : CRM_Queue_DAO_QueueItem|object|null
- Get the full data for an item.
- getName() : string
- Determine the string name of this queue.
- getSpec() : mixed|null
- Get a property from the queueSpec.
- getStatistic() : int|float|null
- Get summary information about items in the queue.
- getStatus() : string|null
- isActive() : bool
- Determine whether this queue is currently active.
- loadQueue() : mixed
- Perform any loading or pre-fetch for an existing queue.
- numberOfItems() : int
- Determine number of items remaining in the queue.
- releaseItem() : mixed
- Return an item that could not be processed.
- setStatus() : void
- Change the status of the queue.
- stealItem() : object
- Get the next item, even if there's an active lease
Constants
DEFAULT_LEASE_TIME
public
mixed
DEFAULT_LEASE_TIME
= 3600
Properties
$queueSpec
protected
array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
$queueSpec
Tags
$_name
private
string
$_name
Methods
__construct()
Create a reference to queue. After constructing the queue, one should usually call createQueue (if it's a new queue) or loadQueue (if it's known to be an existing queue).
public
__construct(array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int} $queueSpec) : mixed
Parameters
- $queueSpec : array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
-
Ex: ['name' => 'my-import', 'type' => 'SqlParallel'] The full definition of queueSpec is defined in CRM_Queue_Service.
Tags
claimItem()
Get the next item.
public
abstract claimItem([int|null $lease_time = NULL ]) : object
Parameters
- $lease_time : int|null = NULL
-
Hold a lease on the claimed item for $X seconds. If NULL, inherit a default.
Return values
object —with key 'data' that matches the inputted data
createItem()
Add a new item to the queue.
public
abstract createItem(mixed $data[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $data : mixed
-
Serializable PHP object or array.
- $options : array<string|int, mixed> = []
-
Queue-dependent options; for example, if this is a priority-queue, then $options might specify the item's priority. Ex: ['release_time' => strtotime('+3 hours')]
createQueue()
Perform any registration or resource-allocation for a new queue
public
abstract createQueue() : mixed
deleteItem()
Remove an item from the queue.
public
abstract deleteItem(object $item) : mixed
Parameters
- $item : object
-
The item returned by claimItem.
deleteQueue()
Release any resources claimed by the queue (memory, DB rows, etc)
public
abstract deleteQueue() : mixed
existsQueue()
Check if the queue exists.
public
abstract existsQueue() : bool
Return values
boolfetchItem()
Get the full data for an item.
public
abstract fetchItem(int|string $id) : CRM_Queue_DAO_QueueItem|object|null
This is a passive peek - it does not claim/steal/release anything.
Parameters
- $id : int|string
-
The unique ID of the task within the queue.
Return values
CRM_Queue_DAO_QueueItem|object|null —$dao
getName()
Determine the string name of this queue.
public
getName() : string
Return values
stringgetSpec()
Get a property from the queueSpec.
public
getSpec(string $field) : mixed|null
Parameters
- $field : string
Return values
mixed|nullgetStatistic()
Get summary information about items in the queue.
public
abstract getStatistic(string $name) : int|float|null
Parameters
- $name : string
-
The desired statistic. Ex:
- 'ready': The number of items ready for execution (not currently claimed, not scheduled for future).
- 'blocked': The number of items that may be runnable in the future, but cannot be run right now.
- 'total': The total number of items known to the queue, regardless of whether their current status.
Return values
int|float|null —The value of the statistic, or NULL if the queue backend does not unsupport this statistic.
getStatus()
public
getStatus() : string|null
Tags
Return values
string|nullisActive()
Determine whether this queue is currently active.
public
isActive() : bool
Tags
Return values
bool —TRUE if runners should continue claiming new tasks from this queue
loadQueue()
Perform any loading or pre-fetch for an existing queue.
public
abstract loadQueue() : mixed
numberOfItems()
Determine number of items remaining in the queue.
public
numberOfItems() : int
Use getStatistic(string $name)
instead.
The definition of numberOfItems()
has become conflicted among different subclasses.
Return values
intreleaseItem()
Return an item that could not be processed.
public
abstract releaseItem(object $item) : mixed
Parameters
- $item : object
-
The item returned by claimItem.
setStatus()
Change the status of the queue.
public
setStatus(string $status) : void
Parameters
- $status : string
-
Ex: 'active', 'draft', 'aborted'
stealItem()
Get the next item, even if there's an active lease
public
abstract stealItem([int $lease_time = NULL ]) : object
Parameters
- $lease_time : int = NULL
-
Seconds.
Return values
object —with key 'data' that matches the inputted data