/**
  *  Will Query the delete a single job
  *
  *  @access public
  *  @return Response
  */
 public function deleteJobAction(Application $app, Request $req, Storage $job)
 {
     $data = array('result' => array(), 'msg' => null);
     # run against api
     $data['result'] = $this->getQueue()->remove($job->getJobId(), new DateTime());
     $data['msg'] = true;
     return $this->response($data, 200);
 }
 /**
  *  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;
 }
 public function testReceiveHandlerDB()
 {
     $gateway = $this->getTableGateway();
     $handler = new QueueSubscriber($gateway);
     $uuid = new UUID(new MersenneRandom(10000));
     $job_name = 'test_job_1';
     $added = new DateTime('01-01-2014 00:00:00');
     # create the transition
     $storage = new Storage();
     $jobID = $uuid->v3($uuid->v4(), $job_name);
     $storage->setJobId($jobID);
     $storage->setDateAdded($added);
     $storage->setJobData(new \stdClass());
     $storage->setState(QueueConfig::STATE_ADD);
     $storage->setRetryLeft(3);
     $event = new QueueReceiveEvent($storage);
     $handler->onReceive($event);
     # assert save result set matches
     $resulting_table = $this->getConnection()->createQueryTable("later_job_queue", "SELECT * FROM later_job_queue ORDER BY dte_add");
     $expected_table = $this->createXmlDataSet(__DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . "receive_handler_result.xml")->getTable("later_job_queue");
     $this->assertTablesEqual($expected_table, $resulting_table);
 }
Example #4
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));
 }
Example #5
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));
 }
Example #6
0
 /**
  *   Add a job to the queue
  *
  *   @access public
  *   @return boolean true if job added
  *   @throws LaterJob\Exception
  *   @param DateTime $now
  *   @param mixed $job_data
  */
 public function send(DateTime $now, $job_data)
 {
     $uuid = $this['uuid'];
     $event = $this['dispatcher'];
     $queue_options = $this['config.queue'];
     $storage = new Storage();
     # generate the uuid for job
     $storage->setJobId($uuid->v3($uuid->v4(), md5(json_encode($job_data))));
     $storage->setDateAdded($now);
     $storage->setJobData($job_data);
     $storage->setState(QueueConfig::STATE_ADD);
     $storage->setRetryLeft($queue_options->getMaxRetry());
     # raise the add event
     $event->dispatch(QueueEventsMap::QUEUE_REC, new QueueReceiveEvent($storage));
     return true;
 }
Example #7
0
 /**
  *  @expectedException LaterJob\Exception
  *  @expectedExceptionMessage Can not transiton from LaterJob\Config\QueueConfig::STATE_FAIL to LaterJob\Config\QueueConfig::STATE_FAIL
  */
 public function testExceptionTransitionFromFailToFail()
 {
     $process_handle = 'a73491a6-ed50-3c17-8e0f-d7279e7a00d9';
     $id = 'a job';
     $data = new \stdClass();
     $mock_event = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $mock_def = $this->getMock('LaterJob\\Config\\QueueConfig');
     $mock_def->expects($this->exactly(2))->method('getLiteral')->with($this->equalTo(QueueConfig::STATE_FAIL))->will($this->returnValue('LaterJob\\Config\\QueueConfig::STATE_FAIL'));
     $storage = new Storage();
     $storage->setJobId($id);
     $storage->setJobData($data);
     $storage->setState(QueueConfig::STATE_FAIL);
     $worker = new Job($storage, $mock_def, $mock_event);
     $worker->fail($process_handle, new DateTime(), 'FAIL on cron');
 }
 public function toArray(Storage $entity)
 {
     return array('jobId' => $entity->getJobId(), 'retryCount' => $entity->getRetryLeft(), 'dateAdded' => $entity->getDateAdded(), 'stateId' => $entity->getState(), 'jobData' => $entity->getJobData(), 'lockTimeout' => $entity->getLockoutTimer(), 'handle' => $entity->getLockoutHandle(), 'retryLast' => $entity->getRetryLast());
 }