Raise the exception occurred queue job event.

@param  string  $connectionName
@param  \Illuminate\Contracts\Queue\Job  $job
@param  \Exception  $e
@return void
179665
protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e)
    {
        $this->events->dispatch(new Events\JobExceptionOccurred(
            $connectionName, $job, $e
        ));
    }
296700
protected function raiseAfterJobEvent($connectionName, $job)
    {
        $this->events->dispatch(new Events\JobProcessed(
            $connectionName, $job
        ));
    }
911272
public function fail($e = null)
    {
        $this->markAsFailed();

        if ($this->isDeleted()) {
            return;
        }

        try {
            // If the job has failed, we will delete it, call the "failed" method and then call
            // an event indicating the job has failed so it can be logged if needed. This is
            // to allow every developer to better keep monitor of their failed queue jobs.
            $this->delete();

            $this->failed($e);
        } finally {
            $this->resolve(Dispatcher::class)->dispatch(new JobFailed(
                $this->connectionName, $this, $e ?: new ManuallyFailedException
            ));
        }
    }
81352
public static function handle($connectionName, $job, $e = null)
    {
        $job->markAsFailed();

        if ($job->isDeleted()) {
            return;
        }

        try {
            // If the job has failed, we will delete it, call the "failed" method and then call
            // an event indicating the job has failed so it can be logged if needed. This is
            // to allow every developer to better keep monitor of their failed queue jobs.
            $job->delete();

            $job->failed($e);
        } finally {
            static::events()->dispatch(new JobFailed(
                $connectionName, $job, $e ?: new ManuallyFailedException()
            ));
        }
    }
42672
public function failed($exception, $connection, $queue, JobPayload $payload)
    {
        $this->connection()->pipeline(function ($pipe) use ($exception, $connection, $queue, $payload) {
            $this->storeJobReference($pipe, 'failed_jobs', $payload);
            $this->storeJobReference($pipe, 'recent_failed_jobs', $payload);

            $pipe->hmset(
                $payload->id(), [
                    'id' => $payload->id(),
                    'connection' => $connection,
                    'queue' => $queue,
                    'name' => $payload->decoded['displayName'],
                    'status' => 'failed',
                    'payload' => $payload->value,
                    'exception' => (string) $exception,
                    'failed_at' => str_replace(',', '.', microtime(true)),
                ]
            );

            $pipe->expireat(
                $payload->id(), Chronos::now()->addMinutes($this->failedJobExpires)->getTimestamp()
            );
        });
    }
573898
public function failed(JobInterface $job)
    {
        $this->checkConnected();
        $this->client->nack($job->getId());
    }
35884
public function onIOError(Connection $conn, \Exception $ex)
    {
        try {
            $conn->tryClose();
        } catch (\Throwable $t) {
            sys_echo("nsq({$conn->getAddr()}) onIOError exception: {$t->getMessage()}");
        } catch (\Exception $ex) {
            sys_echo("nsq({$conn->getAddr()}) onIOError exception: {$ex->getMessage()}");
        }
    }
234736
protected function runJob($job, $connectionName, WorkerOptions $options)
    {
        try {
            $this->process($connectionName, $job, $options);
        } catch (Exception $e) {

            $this->stopWorkerIfLostConnection($e);
        } catch (Throwable $e) {

            $this->stopWorkerIfLostConnection($e);
        }
    }
68753
protected function flushQueueItem(string $connectionName = null, MessageEnvelopeQueue $queue)
    {
        if ($queue->isEmpty()) {
            return;
        }
        $connection = $this->getConnectionHandler()->getConnection($connectionName);
        /* @var AndroidConnection $connection */
        foreach ($queue->getQueue() as $messageEnvelope) {
            /* @var AndroidMessageEnvelope $messageEnvelope */
            $this->sendMessageEnvelope($connection, $messageEnvelope);
        }
        $queue->clear();
    }
865595
protected function raiseExceptionOccurredJobEvent(Job $job, $e)
    {
        $this->getEventsManager()->fire('listener:jobException', $this, [$job, $e]);
    }
363150
public function process($connectionName, $job, WorkerOptions $options)
    {
        try {
            // First we will raise the before job event and determine if the job has already ran
            // over its maximum attempt limits, which could primarily happen when this job is
            // continually timing out and not actually throwing any exceptions from itself.
            $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)
            );
        }
    }
1010854
public function call(Job $job, array $data)
    {
        try {
            $command = $this->setJobInstanceIfNecessary(
                $job, unserialize($data['command'])
            );
        } catch (ModelNotFoundException $e) {
            $this->handleModelNotFound($job, $e);
            return;
        }

        try {
            $this->dispatcher->dispatchNow($command, $this->resolveHandler($job, $command));
        } catch (\Exception $e) {
            if ($command instanceof ErrorHandler) {
                $command->errorHandle($e);
            }

            throw $e;
        } finally {
            app()->instance('QueueCurrentJob', $command);
        }

        if (!$job->hasFailed() && !$job->isReleased()) {
            $this->ensureNextJobInChainIsDispatched($command);
        }

        if (!$job->isDeletedOrReleased()) {
            $job->delete();
        }
    }
1202985
protected function failedJob(Job $job, \Throwable $exception, bool $internal): void
    {
        if ($this->logger) {
            $context = [
                'name' => $job->getName(),
                'arguments' => $job->getArguments(),
                'message' => $exception->getMessage(),
                'retryable' => !$exception instanceof UnrecoverableJobExceptionInterface,
                'internal' => $internal,
            ];
            if (($p = $exception->getPrevious())) {
                $context['cause'] = $p->getMessage();
            }
            $this->logger->error('Job failed.', $context);
        }
        if ($this->eventDispatcher) {
            $this->eventDispatcher->dispatch(self::JOB_FAILED_EVENT, new FailedJobEvent($job, $exception, $internal));
        }
        if ($this->triggerBatchEvents) {
            $batch = new JobBatch([$job]);
            $batch->next();
            $batch->result($exception);
            $this->finishBatch($batch);
        }
    }
272706
protected function raiseFailedJobEvent($connection, Job $job)
    {
        if (isset($this->events)) {
            $this->events->dispatch('nova.queue.failed', array($connection, $job));
        }
    }
21438
public function failJob(Job $job, Throwable $e)
    {
        $this->getEventManager()->trigger('onFailure', $job, [$e]);

        $this->updateStatus($job, self::STATUS_FAILED);

        $this->createFailure($job->getPayload(), $e, $job->getWorker(), $job->getQueue());
    }
901994
protected function failJob($job, Exception $exception)
    {
        if ($job instanceof JobInterface) {
            $payload = $job->getPayload();
            $queue   = $job->getQueue();
        } else {
            $payload = $job;
            $queue   = isset($job['queue']) ? $job['queue'] : null;
        }

        $id = isset($job['id']) ? $job['id'] : null;

        if ($id) {
            try {
                $status = $this->resque->getStatusFactory()->forId($id);
                $status->update(Status::STATUS_FAILED);
            } catch (JobIdException $e) {
                $this->logger->warning($e);
            }
        } // else no status to update

        $this->resque->getFailureBackend()->receiveFailure(
            $payload,
            $exception,
            $this,
            $queue
        );

        $this->getResque()->getStatistic('failed')->incr();
        $this->getStatistic('failed')->incr();
    }
1192689
protected function ensureConnectionIsEstablished($connection)
    {
        if (!$this->isConnectionEstablished($connection)) {
            $message = $this->createConnectionErrorMessage($connection);

            throw new ConnectionException($message);
        }
    }