Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 2
0
 public function update($id)
 {
     $job = $this->jobRepo->findById($id);
     if (!empty(\Request::get('save_restart'))) {
         $this->jobRepo->update($id, ['data' => \Request::get('data'), 'status' => Job::STATUS_RESTART]);
     } elseif (!empty(\Request::get('restart'))) {
         $this->jobRepo->update($id, ['status' => Job::STATUS_RESTART]);
     } elseif (!empty(\Request::get('retry'))) {
         $this->jobRepo->update($id, ['status' => Job::STATUS_RETRY]);
     }
     return \Redirect::route('connector.jobs.show', [$id]);
 }
Exemplo n.º 3
0
 /**
  * @param Job $job
  * @return bool
  * @throws HandlerException
  */
 protected function queueJob(Job $job)
 {
     if ($this->hasHandlerForType($job->type)) {
         $threshold = env('CONNECTOR_QUEUE_HIGH_THRESHOLD');
         $queue = $job->priority >= $threshold ? env('CONNECTOR_QUEUE_HIGH') : env('CONNECTOR_QUEUE_LOW');
         if ($threshold == null || $queue == null) {
             throw new \InvalidArgumentException("Threshold or queue is not set");
         }
         $this->jobRepo->update($job->id, ['status' => 'queued', 'handler' => get_class($this->getHandlerForType($job->type))]);
         \Queue::push(JobQueueHandler::class, ['job_id' => $job->id, 'previous_status' => $job->status], $queue);
         return true;
     }
     $this->jobRepo->update($job->id, ['status' => 'error']);
     $this->logger->error("No handler registered for type '{$job->type}'");
     return false;
 }
Exemplo n.º 4
0
 /**
  * Updates the `reference` column in the `connector_jobs` table
  *
  * @param $reference
  */
 public function setJobReference($reference)
 {
     $this->jobRepo->update($this->job->id, ['reference' => $reference]);
 }