コード例 #1
0
 /**
  *
  * @param Job $job            
  * @param string $componentId            
  * @param string $status            
  * @param string $createdAt            
  * @param string $detailedMessage            
  * @throws InvalidArgumentException
  */
 public function __construct(Job $job, $eventId, $componentId, $status, $createdAt, $detailedMessage)
 {
     $this->jobId = $job->getJobId();
     if (!in_array($componentId, $job->getComponents())) {
         throw new InvalidArgumentException(self::EXC_INVALID_COMPONENT_ID_PROVDED_MESSAGE, self::EXC_INVALID_COMPONENT_ID_PROVIDED_CODE);
     }
     $this->componentId = $componentId;
     $validStatusArr = array(0 => self::STATUS_QUEUED, 1 => self::STATUS_IN_PROGRESS, 2 => self::STATUS_FAILED, 3 => self::STATUS_COMPLETED);
     if (!in_array($status, $validStatusArr)) {
         throw new InvalidArgumentException(self::EXC_INVALID_STATUS_PROVIDED_MESSAGE, self::EXC_INVALID_STATUS_PROVIDED_CODE);
     }
     $this->status = $status;
     $this->detailedMessage = (string) $detailedMessage;
     $this->createdAt = $createdAt;
     $this->eventId = $eventId;
 }
コード例 #2
0
 protected function calculateOverallJobStatusFromMostRecentEventCollection(Job $job, array $mostRecentEventCollection)
 {
     $countQueued = 0;
     $countComplete = 0;
     $countInProgress = 0;
     $countFailed = 0;
     foreach ($mostRecentEventCollection as $statusEvent) {
         /**
          *
          * @var StatusEvent $statusEvent
          */
         switch ($statusEvent->getStatus()) {
             case StatusEvent::STATUS_QUEUED:
                 $countQueued++;
                 break;
             case StatusEvent::STATUS_IN_PROGRESS:
                 $countInProgress++;
                 break;
             case StatusEvent::STATUS_COMPLETED:
                 $countComplete++;
                 break;
             case StatusEvent::STATUS_FAILED:
                 $countFailed++;
                 break;
             default:
                 $countFailed++;
         }
     }
     // fail early!
     if ($countFailed >= 1) {
         if ($countFailed == count($job->getComponents())) {
             return CalculatedJobStatus::STATUS_FAILED;
         }
         if ($countFailed + $countComplete == count($job->getComponents())) {
             return CalculatedJobStatus::STATUS_FAILED;
         }
         return CalculatedJobStatus::STATUS_FAILED_AND_STARTED;
     }
     // if things are only queued but not processing
     if ($countQueued >= 1 && $countInProgress === 0) {
         return CalculatedJobStatus::STATUS_QUEUED;
     }
     // if things are in-progress
     if ($countInProgress >= 1 || $countComplete < count($job->getComponents())) {
         return CalculatedJobStatus::STATUS_IN_PROGRESS;
     }
     // if things are complete but not in-progress
     if ($countComplete === count($job->getComponents()) && $countInProgress === 0) {
         return CalculatedJobStatus::STATUS_COMPLETED;
     }
     throw new CalculatingJobStatusException("An edge case was hit when calculating job status.");
 }