/** * @param JobModel $job * @return bool * @throws HandlerException */ public function handle(JobModel $job) { $success = true; $this->job = $job; list($fromStageNumber, $preloadedData) = $this->prepareStageData($job); foreach ($this->stages as $stage) { try { $stageNumber = $this->getStageNumber($stage); if ($stageNumber < $fromStageNumber) { $this->logger->info("Skipping Stage because of retry"); continue; } $this->oracle->reset($job->id, $stage->getName()); $continue = $this->handleStage($job, $stage, $preloadedData); $this->logger->info("Stage successfully processed"); $this->oracle->reset($job->id); if (!$continue) { break; } } catch (\Exception $e) { $this->logger->warning("Exception was thrown in the JobHandler handle() method, cannot continue (status: error)", ['exception_message' => $e->getMessage(), 'exception_trace' => $e->getTraceAsString()]); $this->jobRepo->update($job->id, ['status' => JobModel::STATUS_ERROR]); $success = false; break; } } if ($success) { $this->jobRepo->update($job->id, ['status' => JobModel::STATUS_HANDLED]); } return $success; }
/** * @param Collection $jobs */ protected function handleJobs(Collection $jobs) { foreach ($jobs as $job) { try { $this->oracle->reset($job->id); $this->logger->info("Queueing new '{$job->type}' Job"); $this->logger->debug('Firing ConnectorRunJobEvent before queueing Job'); \Event::fire(new ConnectorRunJobEvent($job)); $this->queueJob($job); $this->oracle->reset(); } catch (\Exception $e) { $this->logger->critical('Unexpected exception while queueing Job (requires in-depth investigation)', ['oracle' => $this->oracle->asArray(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); } } }