예제 #1
0
 /**
  * @depends testConstruct
  */
 public function testStateToRunning(Job $job)
 {
     $job->setState('running');
     $this->assertEquals('running', $job->getState());
     $this->assertNotNull($startedAt = $job->getStartedAt());
     $job->setState('running');
     $this->assertSame($startedAt, $job->getStartedAt());
     return $job;
 }
 public function __construct(Job $job, $newState, array $allowedStates = array())
 {
     $msg = sprintf('The Job(id = %d) cannot change from "%s" to "%s". Allowed transitions: ', $job->getId(), $job->getState(), $newState);
     $msg .= count($allowedStates) > 0 ? '"' . implode('", "', $allowedStates) . '"' : '#none#';
     parent::__construct($msg);
     $this->job = $job;
     $this->newState = $newState;
     $this->allowedStates = $allowedStates;
 }
 /**
  * @Route("/{id}/retry", name = "jms_jobs_retry_job")
  */
 public function retryJobAction(Job $job)
 {
     $state = $job->getState();
     if (Job::STATE_FAILED !== $state && Job::STATE_TERMINATED !== $state && Job::STATE_INCOMPLETE !== $state) {
         throw new HttpException(400, 'Given job can\'t be retried');
     }
     $retryJob = clone $job;
     $this->getEm()->persist($retryJob);
     $this->getEm()->flush();
     $url = $this->router->generate('jms_jobs_details', array('id' => $retryJob->getId()), false);
     return new RedirectResponse($url, 201);
 }