Пример #1
0
 /**
  *  Transition to the error state
  *
  *  @access public
  *  @param DateTime $when
  *  @param string $msg
  */
 public function error(DateTime $when, $msg = '')
 {
     $this->current_state = WorkerConfig::STATE_ERROR;
     # create the transition entity
     $trans = new Transition();
     $trans->setWorker($this->getId());
     $trans->setState(WorkerConfig::STATE_ERROR);
     $trans->setOccured($when);
     $trans->setMessage($this->definition->getWorkerName() . ' Worker ERROR :: ' . $msg);
     # unlock jobs
     # raise the finish event
     $this->event->dispatch(WorkerEventsMap::WORKER_ERROR, new WorkerTransitionEvent($this, $trans));
 }
Пример #2
0
 /**
  *  Transition a job to Finished 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 finish($handle, DateTime $finish, $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_FINISH)));
     }
     # change the state on the storage
     $this->storage->setState(QueueConfig::STATE_FINISH);
     # create the transition entity
     $trans = new Transition();
     $trans->setJob($this->getId());
     $trans->setState(QueueConfig::STATE_FINISH);
     $trans->setOccured($finish);
     $trans->setMessage(' Job ' . $this->getId() . ' FINISHED :: ' . $msg);
     $trans->setProcessHandle($handle);
     # raise the finish event
     $this->event->dispatch(JobEventsMap::STATE_FINISH, new JobTransitionEvent($this, $trans));
 }