CRM_Queue_Queue_Sql
extends CRM_Queue_Queue
in package
uses
CRM_Queue_Queue_SqlTrait
A queue implementation which stores items in the CiviCRM SQL database
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 registation or resource-allocation for a new queue
- deleteItem() : mixed
- Remove an item from the queue.
- deleteItems() : void
- 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.
- fetchItems() : array<string|int, mixed>
- getName() : string
- Determine the string name of this queue.
- getSpec() : mixed|null
- Get a property from the queueSpec.
- getStatistic() : int|float|null
- 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.
- releaseItems() : void
- setStatus() : void
- Change the status of the queue.
- stealItem() : object
- Get the next item, even if there's an active lease
- freeDAOs() : mixed
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<string|int, mixed> $queueSpec) : mixed
Parameters
- $queueSpec : array<string|int, mixed>
-
Array with keys:
- type: string, required, e.g. "interactive", "immediate", "stomp", "beanstalk"
- name: string, required, e.g. "upgrade-tasks"
- reset: bool, optional; if a queue is found, then it should be flushed; default to TRUE
- (additional keys depending on the queue provider).
claimItem()
Get the next item.
public
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 queue default (
$queueSpec['lease_time']
) or system default (DEFAULT_LEASE_TIME
).
Return values
object —With key 'data' that matches the inputted data.
createItem()
Add a new item to the queue.
public
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 registation or resource-allocation for a new queue
public
createQueue() : mixed
deleteItem()
Remove an item from the queue.
public
deleteItem(CRM_Core_DAO|stdClass $item) : mixed
Parameters
- $item : CRM_Core_DAO|stdClass
-
The item returned by claimItem.
deleteItems()
public
deleteItems(mixed $items) : void
Parameters
- $items : mixed
deleteQueue()
Release any resources claimed by the queue (memory, DB rows, etc)
public
deleteQueue() : mixed
existsQueue()
Check if the queue exists.
public
existsQueue() : bool
Return values
boolfetchItem()
Get the full data for an item.
public
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
fetchItems()
public
fetchItems(array<string|int, mixed> $ids) : array<string|int, mixed>
Parameters
- $ids : array<string|int, mixed>
Return values
array<string|int, mixed>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()
public
getStatistic(string $name) : int|float|null
Parameters
- $name : string
Tags
Return values
int|float|nullgetStatus()
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
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
releaseItem(CRM_Core_DAO $item) : mixed
Parameters
- $item : CRM_Core_DAO
-
The item returned by claimItem.
releaseItems()
public
releaseItems(mixed $items) : void
Parameters
- $items : mixed
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
stealItem([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 queue default (
$queueSpec['lease_time']
) or system default (DEFAULT_LEASE_TIME
).
Return values
object —With key 'data' that matches the inputted data.
freeDAOs()
protected
freeDAOs(mixed $mixed) : mixed
Parameters
- $mixed : mixed