/** * Convert data array into entity * * @return mixed * @param array $data * @access public */ public function build($data) { $object = new Transition(); $object->setTransitionId($data['transition_id']); $object->setOccured($data['dte_occured']); $object->setState($data['state_id']); if (!empty($data['process_handle'])) { $object->setProcessHandle($data['process_handle']); } if (isset($data['transition_msg'])) { if (!empty($data['transition_msg'])) { $object->setMessage($data['transition_msg']); } } if (isset($data['worker_id'])) { if (!empty($data['worker_id'])) { $object->setWorker($data['worker_id']); } } if (isset($data['job_id'])) { if (!empty($data['job_id'])) { $object->setJob($data['job_id']); } } return $object; }
public function testEntityBuilderDemolish() { $transition = new Transition(); $builder = new TransitionBuilder(); $transition_id = 2; $worker_id = 'efgh-ijhg-kjhf-kjjd'; $job_id = 'abcd-efgh-ijkl-mnop'; $state_id = 1; $occured = new DateTime(); $message = 'a transition msg'; $process_handle = 'efgh-ijhg-kjhf-kjjda'; $transition->setTransitionId($transition_id); $transition->setJob($job_id); $transition->setWorker($worker_id); $transition->setOccured($occured); $transition->setMessage($message); $transition->setState($state_id); $transition->setProcessHandle($process_handle); $data = array('transition_id' => $transition_id, 'worker_id' => $worker_id, 'job_id' => $job_id, 'state_id' => $state_id, 'dte_occured' => $occured, 'transition_msg' => $message, 'process_handle' => $process_handle); $converted = $builder->demolish($transition); $this->assertEquals($converted, $data); }
public function testErrorTransitionHandler() { $gateway = $this->getTableGateway(); $handler = new WorkerSubscriber($gateway); $mock_worker = $this->getMockBuilder('LaterJob\\Worker')->disableOriginalConstructor()->getMock(); $uuid = new UUID(new MersenneRandom()); $worker_name = 'test_worker_1'; # create the transition $transition = new Transition(); $transition->setWorker($uuid->v3($uuid->v4(), $worker_name)); $transition->setState(WorkerConfig::STATE_ERROR); $transition->setOccured(new DateTime()); $transition->setMessage('worker error'); # create the event object $transition_event = new WorkerTransitionEvent($mock_worker, $transition); # run through handler $handler->onWorkerError($transition_event); # no exceptions raised by failed recording $this->assertGreaterThan(0, $transition->getTransitionId()); }
public function testTransitionErrorHandler() { $gateway = $this->getTableGateway(); $handler = new JobSubscriber($gateway); $mock_job = $this->getMockBuilder('LaterJob\\Job')->disableOriginalConstructor()->getMock(); $uuid = new UUID(new MersenneRandom()); $worker_name = 'test_job_1'; $process_handler = '01b89534-cf6e-3a63-b7fe-8e6b5a729483'; # create the transition $transition = new Transition(); $transition->setJob($uuid->v3($uuid->v4(), $worker_name)); $transition->setState(QueueConfig::STATE_ERROR); $transition->setOccured(new DateTime()); $transition->setMessage('job encountered error'); $transition->setProcessHandle($process_handler); # create the event object $transition_event = new JobTransitionEvent($mock_job, $transition); # run through handler $handler->onJobError($transition_event); $this->assertGreaterThan(0, $transition->getTransitionId()); }
/** * 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)); }
/** * 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)); }