コード例 #1
0
 /**
  * Regenerates a task (requeues it in the proper tube)
  *
  * @param integer $id
  * @return boolean
  * @throws TaskQueueServiceException
  */
 public function regenerateTask($id)
 {
     $taskEntity = $this->taskRepo->find($id);
     if (!$taskEntity instanceof Task) {
         throw new TaskQueueServiceException("No such task :" . $id, 1);
     }
     if ($taskEntity->getStatus() != Task::STATUS_FAILED) {
         throw new TaskQueueServiceException("Invalid status for task. Current status: '" . $taskEntity->getStatus() . "' must be 'failed' to be able to restart it", 1);
     }
     $data = $taskEntity->getData();
     $taskEntity->setStatus(Task::STATUS_RESTARTED);
     $this->entityManager->flush();
     $parts = explode("::", $data, 2);
     $taskObject = $this->serializer->deserialize($parts[1], $parts[0], 'json');
     $taskObject->setTaskIdentifier($taskEntity->getId());
     $data = get_class($taskObject) . '::' . $this->serializer->serialize($taskObject, 'json');
     $this->beanstalk->useTube($taskEntity->getTube())->put($data);
     return true;
 }
 /**
  * @return void
  */
 public function testIfUseTubeWrapsProperly()
 {
     $this->pheanstalk->shouldReceive('useTube')->with('tube')->once();
     $return = $this->connection->useTube('tube');
     $this->assertEquals($this->connection, $return, 'Return should be the same as the connection');
 }