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 $title
51 * A printable string which describes this task.
53 public function __construct($callback, $arguments, $title = NULL) {
54 $this->callback
= $callback;
55 $this->arguments
= $arguments;
56 $this->title
= $title;
62 * @param array $taskCtx
67 * @return bool, TRUE if task completes successfully
69 public function run($taskCtx) {
70 $args = $this->arguments
;
71 array_unshift($args, $taskCtx);
73 if (is_callable($this->callback
)) {
74 $result = call_user_func_array($this->callback
, $args);
78 throw new Exception('Failed to call callback: ' . print_r($this->callback
));