/** * @param Job $syncJob Laravel queue job * @param $arguments * @return bool * @throws \Unifact\Connector\Exceptions\HandlerException */ public function fire(Job $syncJob, $arguments) { try { $job = $this->jobRepo->findById($arguments['job_id']); $job->setPreviousStatus($arguments['previous_status']); $handler = forward_static_call([$job->handler, 'make']); $this->logger->debug("Preparing Job.."); if (!$handler->prepare()) { $this->logger->error('Handler returned FALSE in prepare() method, see log for details'); // delete Laravel queue job $syncJob->delete(); return false; } $this->logger->debug("Handling Job.."); if ($handler->handle($job) === false) { $this->logger->error('Handler returned FALSE in handle() method, see log for details'); // delete Laravel queue job $syncJob->delete(); return false; } $this->logger->debug("Completing Job.."); $handler->complete(); $this->logger->info('Finished Job successfully'); } catch (\Exception $e) { $this->oracle->exception($e); $this->logger->error('Exception was thrown in JobQueueHandler::fire method.'); $this->jobRepo->update($arguments['job_id'], ['status' => 'error']); // delete Laravel queue job $syncJob->delete(); return false; } // delete Laravel queue job $syncJob->delete(); return true; }
/** * @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()]); } } }
/** * @param array $record */ protected function write(array $record) { $attributes = ['message' => $record['message'], 'level' => $record['level'], 'data' => $record['formatted']]; $attributes = array_merge($attributes, $this->oracle->asArray()); Log::create($attributes); }
/** * @param int $level * @param string $message * @param array $context * @return bool */ public function addRecord($level, $message, array $context = []) { $context = array_merge($this->getOracle()->asArray(), $context); $this->oracle->resetException(); return parent::addRecord($level, $message, $context); }