コード例 #1
0
ファイル: Job.php プロジェクト: icomefromthenet/laterjob
 /**
  *  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));
 }
コード例 #2
0
 /**
  *  Convert data array into entity
  *
  *  @return mixed
  *  @param array $data
  *  @access public
  */
 public function build($data)
 {
     $object = new Storage();
     $object->setJobId($data['job_id']);
     $object->setRetryLeft($data['retry_count']);
     $object->setDateAdded($data['dte_add']);
     $object->setState($data['state_id']);
     $object->setJobData($data['job_data']);
     if ($data['lock_timeout'] instanceof DateTime) {
         $object->setLockoutTimer($data['lock_timeout']);
     }
     if ($data['retry_last'] instanceof DateTime) {
         $object->setRetryLast($data['lock_timeout']);
     }
     if ($data['handle'] !== null) {
         $object->setLockoutHandle($data['handle']);
     }
     return $object;
 }
コード例 #3
0
 public function testDemolish()
 {
     $storage = new Storage();
     $builder = new StorageBuilder();
     $dte_added = new DateTime();
     $job_data = new \stdClass();
     $job_id = '67b9a976-2edd-3e6e-adc3-22adeb5b3949';
     $lockout_handle = md5($job_id);
     $lockout_timer = new DateTime();
     $retry = 3;
     $state = 1;
     $retry_last = new DateTime();
     $storage->setDateAdded($dte_added);
     $storage->setJobData($job_data);
     $storage->setJobId($job_id);
     $storage->setLockoutHandle($lockout_handle);
     $storage->setLockoutTimer($lockout_timer);
     $storage->setRetryLeft($retry);
     $storage->setRetryLast($retry_last);
     $storage->setState($state);
     $this->assertEquals(array('job_id' => $job_id, 'retry_count' => $retry, 'dte_add' => $dte_added, 'state_id' => $state, 'job_data' => $job_data, 'handle' => $lockout_handle, 'lock_timeout' => $lockout_timer, 'retry_last' => $retry_last), $builder->demolish($storage));
 }