Exemplo n.º 1
0
 /**
  * Handle the queue job.
  *
  * @param LaravelJob $laravelJob
  * @param mixed $data
  */
 public function fire(LaravelJob $laravelJob, $data)
 {
     $job = null;
     try {
         $job = $this->jobs->find($data['job_id']);
         // Check if the job is valid (not expired and ready). This might
         // happen on some timing edge cases.
         if (!$job->ready()) {
             $laravelJob->delete();
             return;
         }
         // Look for a task handler
         $handler = $this->resolver->resolve($job);
         if ($handler->getSpec() instanceof Spec) {
             $result = $handler->getSpec()->check($job->getData());
             if ($result->failed()) {
                 $laravelJob->delete();
                 $this->jobs->giveUp($job, 'Task data does not pass Spec.');
                 return;
             }
         }
         // Execute the handler
         $this->jobs->started($job, "Task handler started.\n");
         $handler->fire($job, $this->scheduler);
         $this->jobs->complete($job);
     } catch (ModelNotFoundException $e) {
         // Here we just cancel the queue job since there is no point in
         // retrying.
         $laravelJob->delete();
     } catch (UnresolvableException $e) {
         // Here we just cancel the queue job since there is no point in
         // retrying.
         $laravelJob->delete();
         $this->jobs->giveUp($job, 'Task handler was not found');
     } catch (Exception $e) {
         // If we were not able to find the job, just give up.
         if (is_null($job)) {
             $laravelJob->delete();
             return;
         }
         if ($job->hasAttemptsLeft()) {
             $this->jobs->release($job);
             $laravelJob->release();
             return;
         }
         $this->jobs->fail($job, 'Exception: ' . $e->getMessage());
         $laravelJob->delete();
     }
 }
 public function getReferenceSingle(HandlerResolverInterface $resolver, ConferenceContext $context, Request $request)
 {
     $taskName = $request->query->get('id');
     $handler = $resolver->instantiate($taskName);
     $defaults = $handler->getDefaults();
     $types = $handler->getTypes();
     return new Card([], [new CardHeader([], 'Reference for task:'), new CardBlock([], [new HeaderOne(['class' => 'display-one'], $taskName), new Paragraph(['class' => 'lead'], $handler->getDescription())]), new SimpleTable(['Field Name', 'Type', 'Default', 'Description'], Std::map(function ($description, $field) use($types, $defaults) {
         return [$field, Arr::dotGet($types, $field, '-'), (string) Arr::dotGet($defaults, $field, '-'), $description];
     }, $handler->getReference())), new CardBlock([], [new HeaderSix([], 'Example usage:'), new PreformattedText([], json_encode($defaults, JSON_PRETTY_PRINT))])]);
 }