Process a given job from the queue.

@param  string  $connection
@param  \Nova\Queue\Job  $job
@param  int  $maxTries
@param  int  $delay
@return void

@throws \Exception
166179
public function process($connection, Job $job, $maxTries = 0, $delay = 0)
    {
        if (($maxTries > 0) && ($job->attempts() > $maxTries)) {
            return $this->logFailedJob($connection, $job);
        }

        // First we will raise the before job event and fire off the job. Once it is done
        // we will see if it will be auto-deleted after processing and if so we will go
        // ahead and run the delete method on the job. Otherwise we will just keep moving.

        try {
            $this->raiseBeforeJobEvent($connection, $job);

            $job->handle();

            if ($job->autoDelete()) {
                $job->delete();
            }

            $this->raiseAfterJobEvent($connection, $job);

            return array('job' => $job, 'failed' => false);
        }

        // If we catch an exception, we will attempt to release the job back onto
        // the queue so it is not lost. This will let is be retried at a later
        // time by another listener (or the same one). We will do that here.

        catch (Exception $e) {
            if (! $job->isDeleted()) {
                $job->release($delay);
            }

            throw $e;
        }
        catch (Throwable $e) {
            if (! $job->isDeleted()) {
                $job->release($delay);
            }

            throw $e;
        }
    }
761147
public function release($queue, $job, $delay)
    {
        return $this->pushToDatabase($queue, $job->payload, $delay, $job->attempts);
    }
509167
protected function runWorker($connection, $queue, $delay, $memory, $daemon = false)
	{
		$this->worker->setDaemonExceptionHandler(
			$this->laravel['Illuminate\Contracts\Debug\ExceptionHandler']
		);

		if ($daemon) {
			$this->worker->setCache($this->laravel['cache']->driver());

			return $this->worker->daemon(
				$connection, $queue, $delay, $memory,
				$this->option('sleep'), $this->option('tries')
			);
		}

		return $this->worker->pop(
			$connection, $queue, $delay,
			$this->option('sleep'), $this->option('tries')
		);
	}
895858
public function executeJob(Job $job, int $retryLimit = 0): void
    {
        // This is here so that if executeJob is called with out startBatch the events will still be called
        $this->triggerBatchEvents = !$this->batchStarted;
        if ($this->triggerBatchEvents) {
            $this->startBatch(new JobBatch([$job]));
        }

        $internal = false;

        if ($this->logger) {
            $this->logger->debug('Start a job.', [
                'name' => $job->getName(),
                'arguments' => $job->getArguments(),
            ]);
        }

        try {
            $worker = $this->workersMap->get($job->getName());
            if (!$worker instanceof Worker) {
                throw new InvalidWorkerException("The worker {$job->getName()} is not an instance of ".Worker::class);
            }
            $internal = $worker instanceof InternalWorker;
            if ($this->eventDispatcher) {
                $this->eventDispatcher->dispatch(self::JOB_START_EVENT, new StartJobEvent($job, $internal));
            }
            $worker->execute($job->getArguments());
        } catch (NotFoundExceptionInterface $e) {
            $unrecoverable = new UnrecoverableJobException("Missing worker {$job->getName()}", 0, $e);
            $this->failedJob($job, $unrecoverable, $internal);

            throw $unrecoverable;
        } catch (UnrecoverableJobExceptionInterface $e) {
            $this->failedJob($job, $e, $internal);

            throw $e;
        } catch (\Throwable $e) {
            if (!$job instanceof RetryableJob) {
                $unrecoverable = new UnrecoverableJobException('Job failed and is not retryable', 0, $e);
                $this->failedJob($job, $unrecoverable, $internal);

                throw $unrecoverable;
            }

            if ($job->getRetryCount() >= $retryLimit) {
                $unrecoverable = new UnrecoverableJobException('Job reached retry limit and won\'t be retried again', 0, $e);
                $this->failedJob($job, $unrecoverable, $internal);

                throw $unrecoverable;
            }

            $this->failedJob($job, $e, $internal);

            throw $e;
        }
        $this->finishJob($job, $internal);
    }
785251
public function daemon( $connectionName, $queue = null, $delay = 0, $memory = 128, $sleep = 3, $maxTries = 0 )
	{
		$lastRestart = $this->getTimestampOfLastQueueRestart();

		while ( true )
		{
			if ( $this->daemonShouldRun() )
			{
				$this->runNextJobForDaemon( $connectionName, $queue, $delay, $sleep, $maxTries );
			}
			else
			{
				$this->sleep( $sleep );
			}

			if ( $this->memoryExceeded( $memory ) || $this->queueShouldRestart( $lastRestart ) )
			{
				$this->stop();
			}
		}
	}
344000
public function runNextJob($connection, $queue = null, $delay = 0, $sleep = 3, $maxTries = 0)
    {
        $job = $this->getNextJob(
            $this->manager->connection($connection), $queue
        );

        // 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)) {
            return $this->runJob($job, $connection, $maxTries, $delay);
        }

        $this->sleep($sleep);

        return array('job' => null, 'failed' => false);
    }
768638
public function process($connectionName, $job, WorkerOptions $options)
    {
        $startTime = microtime(true);

        try {
            parent::process($connectionName, $job, $options);
        } catch (Exception $e) {
            $this->recordJobException($e);
        } catch (Throwable $e) {
            $this->recordJobException($e);
        } finally {
            $this->recordJobEnd($startTime, $job->resolveName());
        }
    }
751775
protected function runJob($job, $connection, $maxTries, $delay)
    {
        try {
            return $this->process($connection, $job, $maxTries, $delay);
        }
        catch (Exception $e) {
            $this->handleException($e);
        }
        catch (Throwable $e) {
            $this->handleException(new FatalThrowableError($e));
        }
    }
307226
public function deleteAndRelease($queue, $job, $delay)
    {
        parent::deleteAndRelease($queue, $job, $delay);

        $this->event($this->getQueue($queue), new JobReleased($job->getReservedJob()));
    }
948655
public function prepareForNextAttempt($job_id, $previous_attempts, $delay = 0)
    {
        $this->connection->execute('UPDATE `' . self::JOBS_TABLE_NAME . '` SET `available_at` = ?, `reservation_key` = NULL, `reserved_at` = NULL, `attempts` = ? WHERE `id` = ?', date('Y-m-d H:i:s', time() + $delay), $previous_attempts + 1, $job_id);
    }
1326697
protected function runNextJobForDaemon($connectionName, $queue, $delay, $sleep, $maxTries)
	{
		try
		{
			$this->pop($connectionName, $queue, $delay, $sleep, $maxTries);
		}
		catch (Exception $e)
		{
			if ($this->exceptions) $this->exceptions->report($e);
		}
	}
348901
public function later($delay, $job, $data = '', $queue = null)
    {
        return $this->pushToDatabase($queue, $this->createPayload(
            $job, $this->getQueue($queue), $data
        ), $delay);
    }
861171
public function enqueue(Job\WrappedJob $job) {
        $serialized = Job\serializeJobs([$job->withQueueProvider('sync')]);
        $res = unserialize($this->worker->work($serialized));
        if ($res[0]->isFailed()) {
            throw new \RuntimeException("Job Failed - " . json_encode($res[0], JSON_PRETTY_PRINT));
        }
    }
666768
protected function raiseBeforeJobEvent($connection, Job $job)
    {
        if (isset($this->events)) {
            $this->events->dispatch('nova.queue.processing', array($connection, $job));
        }
    }
1087044
public function later($delay, $job, $data = '', $queue = null)
    {
        $timestamp = time() + $this->getSeconds($delay);
        $id = $this->storeJob($job, $data, $queue, $timestamp);

        return 0;
    }
1146862
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($job, $maxTries)
    {
        if ($maxTries === 0 || $job->attempts() <= $maxTries) {
            return;
        }
        $e = new Exception(
            'A queued job has been attempted too many times. The job may have previously timed out.'
        );
        $this->failJob($job, $e);
        throw $e;
    }
85277
protected function runWorker($connection, $queue)
    {
        $this->worker->setCache($this->laravel['cache']->driver());

        return $this->worker->{$this->option('once') ? 'runNextJob' : 'daemon'}(
            $connection, $queue, $this->gatherWorkerOptions()
        );
    }