/** * 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 testStartTranstionExceptionMissingOccuredColumn() { $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_START); $transition->setMessage('worker starting'); # create the event object $transition_event = new WorkerTransitionEvent($mock_worker, $transition); # run through handler $handler->onWorkerStart($transition_event); $handler->onWorkerStart($transition_event); }
/** * 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)); }