Exemplo n.º 1
0
 function releaseWorker($workerId)
 {
     /** @var $worker WorkerData */
     $worker = $this->_workerRepository->getWorker($workerId);
     if ($worker == null) {
         throw new ManagerException("Worker with id {$workerId} does'nt exist", self::SERVICE_CATEGORY, self::FAULT_WORKER_DOESNT_EXIST);
     }
     if ($worker->status->getValue() !== WorkerStatusEnum::IN_PROGRESS) {
         throw new ManagerException("Worker with is {$workerId} is not running", self::SERVICE_CATEGORY, self::FAULT_WORKER_IS_NOT_RUNNING);
     }
     $workerData = new WorkerData();
     $workerData->id = $workerId;
     $workerData->pid = null;
     $workerData->startDateTime = null;
     $workerData->endDateTime = new DateTime();
     $workerData->status = new WorkerStatusEnum(WorkerStatusEnum::ACTIVE);
     $this->_workerRepository->updateWorkerStatus($workerData);
 }
Exemplo n.º 2
0
 private function handleException(WorkerException $exception)
 {
     $workerData = new WorkerData();
     $workerData->id = $this->_worker->getId();
     $workerData->status = new WorkerStatusEnum(WorkerStatusEnum::FAILED);
     $workerData->endDateTime = new DateTime();
     $this->_workerRepository->updateWorkerStatus($workerData);
     $event = new WorkerEvent();
     $event->status = new WorkerEventStatusEnum(WorkerEventStatusEnum::EVENT_ON_FAILED);
     $event->data = $exception;
     $this->trigger(self::EVENT_WORKER_STATUS, $event);
     $message = "worker {$workerData->id} failed, Exception \"{$exception->getMessage()}\"";
     do {
         $internalException = $exception->getInternalException();
         if ($internalException !== null) {
             $message .= ", \t\nInternal exception: \"{$internalException->getMessage()}\" :";
             $message .= "\t\t\n Trace:" . $internalException->getTraceAsString();
         }
         $exception = $internalException;
     } while ($internalException !== null && $internalException instanceof InternalExceptionBase);
     $this->log($message, Logger::LEVEL_ERROR);
 }