/** * Sets the current status of this step * * @param BatchStatus $status the current status of this step * * @return $this */ public function setStatus(BatchStatus $status) { $this->status = $status->getValue(); return $this; }
/** * Run the specified job, handling all listener and repository calls, and * delegating the actual processing to {@link #doExecute(JobExecution)}. * @param JobExecution $jobExecution * * @see Job#execute(JobExecution) * @throws StartLimitExceededException if start limit of one of the steps was exceeded */ public final function execute(JobExecution $jobExecution) { $this->dispatchJobExecutionEvent(EventInterface::BEFORE_JOB_EXECUTION, $jobExecution); try { if ($jobExecution->getStatus()->getValue() !== BatchStatus::STOPPING) { $jobExecution->setStartTime(new \DateTime()); $this->updateStatus($jobExecution, BatchStatus::STARTED); $this->jobRepository->updateJobExecution($jobExecution); $this->doExecute($jobExecution); } else { // The job was already stopped before we even got this far. Deal // with it in the same way as any other interruption. $jobExecution->setStatus(new BatchStatus(BatchStatus::STOPPED)); $jobExecution->setExitStatus(new ExitStatus(ExitStatus::COMPLETED)); $this->jobRepository->updateJobExecution($jobExecution); $this->dispatchJobExecutionEvent(EventInterface::JOB_EXECUTION_STOPPED, $jobExecution); } } catch (JobInterruptedException $e) { $jobExecution->setExitStatus($this->getDefaultExitStatusForFailure($e)); $jobExecution->setStatus(new BatchStatus(BatchStatus::max(BatchStatus::STOPPED, $e->getStatus()->getValue()))); $jobExecution->addFailureException($e); $this->jobRepository->updateJobExecution($jobExecution); $this->dispatchJobExecutionEvent(EventInterface::JOB_EXECUTION_INTERRUPTED, $jobExecution); } catch (\Exception $e) { $jobExecution->setExitStatus($this->getDefaultExitStatusForFailure($e)); $jobExecution->setStatus(new BatchStatus(BatchStatus::FAILED)); $jobExecution->addFailureException($e); $this->jobRepository->updateJobExecution($jobExecution); $this->dispatchJobExecutionEvent(EventInterface::JOB_EXECUTION_FATAL_ERROR, $jobExecution); } if ($jobExecution->getStatus()->getValue() <= BatchStatus::STOPPED && count($jobExecution->getStepExecutions()) === 0) { /* @var ExitStatus */ $exitStatus = $jobExecution->getExitStatus(); $noopExitStatus = new ExitStatus(ExitStatus::NOOP); $noopExitStatus->addExitDescription("All steps already completed or no steps configured for this job."); $jobExecution->setExitStatus($exitStatus->logicalAnd($noopExitStatus)); $this->jobRepository->updateJobExecution($jobExecution); } $this->dispatchJobExecutionEvent(EventInterface::AFTER_JOB_EXECUTION, $jobExecution); $jobExecution->setEndTime(new \DateTime()); $this->jobRepository->updateJobExecution($jobExecution); }
public function testGetAllLabels() { $expectedLabels = array(BatchStatus::COMPLETED => 'COMPLETED', BatchStatus::STARTING => 'STARTING', BatchStatus::STARTED => 'STARTED', BatchStatus::STOPPING => 'STOPPING', BatchStatus::STOPPED => 'STOPPED', BatchStatus::FAILED => 'FAILED', BatchStatus::ABANDONED => 'ABANDONED', BatchStatus::UNKNOWN => 'UNKNOWN'); $this->assertEquals($expectedLabels, BatchStatus::getAllLabels()); }