Illuminate\Queue\Worker::process PHP Метод

process() публичный Метод

Process a given job from the queue.
public process ( string $connectionName, Illuminate\Contracts\Queue\Job $job, WorkerOptions $options ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$options WorkerOptions
Результат void
    public function process($connectionName, $job, WorkerOptions $options)
    {
        try {
            $this->raiseBeforeJobEvent($connectionName, $job);
            $this->markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $job, (int) $options->maxTries);
            // Here we will fire off the job and let it process. We will catch any exceptions so
            // they can be reported to the developers logs, etc. Once the job is finished the
            // proper events will be fired to let any listeners know this job has finished.
            $job->fire();
            $this->raiseAfterJobEvent($connectionName, $job);
        } catch (Exception $e) {
            $this->handleJobException($connectionName, $job, $options, $e);
        } catch (Throwable $e) {
            $this->handleJobException($connectionName, $job, $options, new FatalThrowableError($e));
        }
    }

Usage Example

 /**
  *  Process the job
  * 
  */
 protected function processJob($connectionName, $id)
 {
     $manager = $this->worker->getManager();
     $connection = $manager->connection($connectionName);
     $job = $connection->getJobFromId($id);
     // If we're able to pull a job off of the stack, we will process it and
     // then immediately return back out. If there is no job on the queue
     // we will "sleep" the worker for the specified number of seconds.
     if (!is_null($job)) {
         $sleep = max($job->getDatabaseJob()->available_at - time(), 0);
         sleep($sleep);
         return $this->worker->process($manager->getName($connectionName), $job);
     }
     return ['job' => null, 'failed' => false];
 }