/** * 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); }
/** * @expectedException LaterJob\Exception */ public function testExceptionStartHandlerMissingDateColumn() { $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_START); $transition->setMessage('job started'); $transition->setProcessHandle($process_handler); # create the event object $transition_event = new JobTransitionEvent($mock_job, $transition); # run through handler $handler->onJobStart($transition_event); }
/** * 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)); }