/** * Format a result record which describes whether the task completed. * * @param bool $isOK * TRUE if the task completed successfully. * @param Exception|NULL $exception * If applicable, an unhandled exception that arose during execution. * * @return array * (is_error => bool, is_continue => bool, numberOfItems => int) */ public function formatTaskResult($isOK, $exception = NULL) { $numberOfItems = $this->queue->numberOfItems(); $result = array(); $result['is_error'] = $isOK ? 0 : 1; $result['exception'] = $exception; $result['last_task_title'] = isset($this->lastTaskTitle) ? $this->lastTaskTitle : ''; $result['numberOfItems'] = $this->queue->numberOfItems(); if ($result['numberOfItems'] <= 0) { // nothing to do $result['is_continue'] = 0; } elseif ($isOK) { // more tasks remain, and this task succeeded $result['is_continue'] = 1; } elseif ($this->errorMode == CRM_Queue_Runner::ERROR_CONTINUE) { // more tasks remain, and we can disregard this error $result['is_continue'] = 1; } else { // more tasks remain, but we can't disregard the error $result['is_continue'] = 0; } return $result; }
/** * 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). * * @param array $queueSpec * 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). */ public function __construct($queueSpec) { parent::__construct($queueSpec); }