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.
28 * @var mixed, serializable
33 * @var array, serializable
38 * @var string, NULL-able
43 * @param mixed $callback
44 * Serializable, a callable PHP item; must accept at least one argument
45 * (CRM_Queue_TaskContext).
46 * @param array $arguments
47 * Serializable, extra arguments to pass to the callback (in order).
48 * @param string $title
49 * A printable string which describes this task.
51 public function __construct($callback, $arguments, $title = NULL) {
52 $this->callback
= $callback;
53 $this->arguments
= $arguments;
54 $this->title
= $title;
60 * @param array $taskCtx
65 * @return bool, TRUE if task completes successfully
67 public function run($taskCtx) {
68 $args = $this->arguments
;
69 array_unshift($args, $taskCtx);
71 if (is_callable($this->callback
)) {
72 $result = call_user_func_array($this->callback
, $args);
76 throw new Exception('Failed to call callback: ' . print_r($this->callback
));