/** * Transition a job to error state * * @access public * @param string $handle The worker's handle * @param DateTime $start * @param string $msg * @throws LaterJob\Exception when starting state fails */ public function error($handle, DateTime $when, $msg = '') { $current = $this->storage->getState(); if ($current !== QueueConfig::STATE_START) { throw new LaterJobException(sprintf('Can not transiton from %s to %s', $this->getCurrentState(), $this->config->getLiteral(QueueConfig::STATE_ERROR))); } # change the state on the storage $this->storage->setState(QueueConfig::STATE_ERROR); # set the timer for next retry $wait = clone $when; $t = $wait->getTimestamp(); $v = $this->config->getRetryTimer(); $wait->setTimestamp($t + $v); $this->storage->setRetryLast($wait); # remove one off recount $count = $this->storage->getRetryLeft(); if ($count > 0) { $this->storage->setRetryLeft($count - 1); } # create the transition entity $trans = new Transition(); $trans->setJob($this->getId()); $trans->setState(QueueConfig::STATE_ERROR); $trans->setOccured($when); $trans->setMessage(' Job ' . $this->getId() . ' ERROR :: ' . $msg); $trans->setProcessHandle($handle); # raise the error event $this->event->dispatch(JobEventsMap::STATE_ERROR, new JobTransitionEvent($this, $trans)); }
public function testQueueConfigDefaults() { $config = new QueueConfig(); $data = array('queue' => array('mean_service_time' => 60 * 60 * 1, 'max_retry' => 1, 'retry_timer' => 60 * 60 * 1)); $config->parse($data); $this->assertEquals($data['queue']['mean_service_time'], $config->getMeanServiceTime()); $this->assertEquals($data['queue']['max_retry'], $config->getMaxRetry()); $this->assertEquals($data['queue']['retry_timer'], $config->getRetryTimer()); }