3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * A task is an item that can be enqueued and later executed
15 class CRM_Queue_Task
{
18 * Task was performed successfully.
20 const TASK_SUCCESS
= 1;
23 * Task failed and should not be retried.
45 * @param mixed $callback
46 * Serializable, a callable PHP item; must accept at least one argument
47 * (CRM_Queue_TaskContext).
48 * @param array $arguments
49 * Serializable, extra arguments to pass to the callback (in order).
50 * @param string|null $title
51 * A printable string which describes this task.
53 public function __construct($callback, array $arguments = [], ?
string $title = NULL) {
54 $this->callback
= $callback;
55 $this->arguments
= $arguments;
56 $this->title
= $title;
62 * @param \CRM_Queue_TaskContext $taskCtx
65 * TRUE if task completes successfully.
66 * FALSE or exception if task fails.
68 public function run($taskCtx) {
69 $args = $this->arguments
;
70 array_unshift($args, $taskCtx);
72 if (is_callable($this->callback
)) {
73 $result = call_user_func_array($this->callback
, $args);
77 throw new Exception('Failed to call callback: ' . print_r($this->callback
));