Documentation

CRM_Queue_Service
in package

The queue service provides an interface for creating or locating queues. Note that this approach hides the details of data-storage: different queue-providers may store the queue content in different ways (in memory, in SQL, or in an external service).

$queue = CRM_Queue_Service::singleton()->create(array(
  'type' => 'interactive',
  'name' => 'upgrade-tasks',
));
$queue->createItem($myData);

// Some time later...
$item = $queue->claimItem();
if ($item) {
  if (my_process($item->data)) {
    $queue->deleteItem($item);
  } else {
    $queue->releaseItem($item);
  }
}

Table of Contents

Properties

$queues  : array<string|int, mixed>
Queues.
$_singleton  : mixed
$commonFields  : array<string|int, string>
List of fields which are shared by `$queueSpec` and `civicrm_queue`.

Methods

__construct()  : mixed
Class constructor.
create()  : CRM_Queue_Queue
Create a queue. If one already exists, then it will be reused.
load()  : CRM_Queue_Queue
Look up an existing queue.
singleton()  : CRM_Queue_Service
FIXME: Singleton pattern should be removed when dependency-injection becomes available.
validateQueueSpec()  : void
Assert that the queueSpec is well-formed.
findCreateQueueSpec()  : array<string|int, mixed>
Find/create the queue-spec. Specifically:
findQueueSpec()  : array<string|int, mixed>|null
getQueueClass()  : string
Convert a queue "type" name to a class name.
instantiateQueueObject()  : CRM_Queue_Queue

Properties

$queues

Queues.

public array<string|int, mixed> $queues

Format is (string $queueName => CRM_Queue_Queue).

$_singleton

protected static mixed $_singleton

$commonFields

List of fields which are shared by `$queueSpec` and `civicrm_queue`.

private static array<string|int, string> $commonFields = ['name', 'type', 'runner', 'status', 'error', 'batch_limit', 'lease_time', 'retry_limit', 'retry_interval']
Tags
readonly

Methods

__construct()

Class constructor.

public __construct() : mixed

create()

Create a queue. If one already exists, then it will be reused.

public create(array<string|int, mixed> $queueSpec) : CRM_Queue_Queue
Parameters
$queueSpec : array<string|int, mixed>

Array with keys:

  • type: string, required, e.g. Sql, SqlParallel, Memory
  • 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).
  • is_persistent: bool, optional; if true, then this queue is loaded from civicrm_queue list
  • runner: string, optional; if given, then items in this queue can run automatically via hook_civicrm_queueRun_{$runner}
  • status: string, required for runnable-queues; specify whether the runner is currently active ex: 'active', 'draft', 'completed'
  • error: string, required for runnable-queues; specify what to do with unhandled errors ex: "drop" or "abort"
  • batch_limit: int, Maximum number of items in a batch.
  • lease_time: int, When claiming an item (or batch of items) for work, how long should the item(s) be reserved. (Seconds)
  • retry_limit: int, Number of permitted retries. Set to zero (0) to disable.
  • retry_interval: int, Number of seconds to wait before retrying a failed execution.
Return values
CRM_Queue_Queue

load()

Look up an existing queue.

public load(array<string|int, mixed> $queueSpec) : CRM_Queue_Queue
Parameters
$queueSpec : array<string|int, mixed>

Array with keys:

  • type: string, required, e.g. Sql, SqlParallel, Memory
  • name: string, required, e.g. "upgrade-tasks"
  • (additional keys depending on the queue provider).
  • is_persistent: bool, optional; if true, then this queue is loaded from civicrm_queue list
Return values
CRM_Queue_Queue

singleton()

FIXME: Singleton pattern should be removed when dependency-injection becomes available.

public static & singleton([bool $forceNew = FALSE ]) : CRM_Queue_Service
Parameters
$forceNew : bool = FALSE

TRUE if a new instance must be created.

Return values
CRM_Queue_Service

validateQueueSpec()

Assert that the queueSpec is well-formed.

public validateQueueSpec(array<string|int, mixed> $queueSpec) : void
Parameters
$queueSpec : array<string|int, mixed>
Tags
throws
CRM_Core_Exception

findCreateQueueSpec()

Find/create the queue-spec. Specifically:

protected findCreateQueueSpec(array<string|int, mixed> $queueSpec) : array<string|int, mixed>
  • If there is a stored queue, use its spec.
  • If there is no stored queue, and if we have enough information, then create queue.
Parameters
$queueSpec : array<string|int, mixed>
Tags
throws
CRM_Core_Exception
Return values
array<string|int, mixed>

Updated queueSpec.

findQueueSpec()

protected findQueueSpec(array<string|int, mixed> $queueSpec) : array<string|int, mixed>|null
Parameters
$queueSpec : array<string|int, mixed>
Return values
array<string|int, mixed>|null

getQueueClass()

Convert a queue "type" name to a class name.

protected getQueueClass(string $type) : string
Parameters
$type : string
  • type: string, required, e.g. Sql, SqlParallel, Memory
Return values
string

Class-name

instantiateQueueObject()

protected instantiateQueueObject(array<string|int, mixed> $queueSpec) : CRM_Queue_Queue
Parameters
$queueSpec : array<string|int, mixed>

See create().

Return values
CRM_Queue_Queue

        
On this page

Search results