Raise the exception occurred queue job event.

@param  \Illuminate\Contracts\Queue\Job  $job
@param  \Exception  $e
@return void
176973
protected function raiseExceptionOccurredJobEvent(Job $job, $e)
    {
        if ($this->container->bound('events')) {
            $this->container['events']->dispatch(new Events\JobExceptionOccurred($this->connectionName, $job, $e));
        }
    }
655076
protected function executeJob(Job $job): ?\Throwable
    {
        try {
            $this->jobExecutor->executeJob($job, $this->retryLimit);
        } catch (\Throwable $e) {
            return $e;
        }

        return null;
    }
815308
public function jobException(Event $event)
    {
        $data = $event->data();
        $this->logger()->alert(sprintf('Exception: "%s"', $data['exception']->getMessage()));
    }
632449
public static function onFailure(\Exception $e, \Resque_Job $job)
    {
        /** @var JobBase $failedJob */
        $failedJob = $job->getInstance();
        $failedJob->errorLog('Caught exception in '. get_called_class() . ': ' . $e->getMessage());
        $failedJob->getStat()->increment($failedJob->getStatFailureIncrementKey());
        throw $e;
    }
1010220
public function deleteReserved($queue, $job)
    {
        parent::deleteReserved($queue, $job);

        $this->event($this->getQueue($queue), new JobDeleted($job, $job->getReservedJob()));
    }
666768
protected function raiseBeforeJobEvent($connection, Job $job)
    {
        if (isset($this->events)) {
            $this->events->dispatch('nova.queue.processing', array($connection, $job));
        }
    }
1157496
private function runJob($job)
    {
        try {
            $this->logger->notice("Job #{$this->currentJobId} [{$job->getName()}] started.");
            $status = $this->broker->getStatus($job->getId());
            $status['status'] = Job::STATUS_RUNNING;
            $status['started'] = date(DATE_RFC3339_EXTENDED);
            $this->broker->setStatus($job->getId(), $status);
            $job->setup();
            $response = $job->go();
            $job->tearDown();
            $status['status'] = Job::STATUS_FINISHED;
            $status['finished'] = date(DATE_RFC3339_EXTENDED);
            $status['response'] = $response;
            $this->broker->setStatus($job->getId(), $status);
            $this->logger->notice("Job #{$this->currentJobId} [{$job->getName()}] finished.");
        } catch (\Exception $e) {
            $status['status'] = Job::STATUS_FAILED;
            $status['failed'] = date(DATE_RFC3339_EXTENDED);
            $this->broker->setStatus($job->getId(), $status);
            $this->logException($e, "Job #{$this->currentJobId}  [{$job->getName()}] Exception");
            $this->logger->alert("Job #{$this->currentJobId}  [{$job->getName()}] died.");
        }
    }
506147
protected function markJobAsFailedIfAlreadyExceedsMaxAttempts(Job $job, $maxTries)
    {
        if ($maxTries === 0 || $job->attempts() <= $maxTries) {
            return;
        }

        $this->failJob($job, $e = new \RuntimeException('A queued job has been attempted too many times. The job may have previously timed out.'));

        throw $e;
    }
1312774
private function handleError(\Exception $e, $interimName)
    {
        // Console feedback
        $this->output->writeln('<error>A ' . $interimName . ' job failed. The exception returned was:</error>');
        $this->output->writeln('<error>    ' . $e->getMessage() . '</error>');
        $this->output->writeln('<error>Backtrace:</error>');
        $this->output->writeln('<error>' . $e->getTraceAsString() . '</error>');

        // Application log
        $this->app['logger.system']->error("$interimName job failed: " . substr($e->getTraceAsString(), 0, 1024), ['event' => 'cron']);
    }
141556
public function perform(JobInterface $job)
    {
        try {
            $job->perform();
        } catch (Exception $e) {
            $this->logger->notice('{job} failed: {exception}', array(
                'job'     => $job,
                'exception' => $e
            ));
            $this->failJob($job, $e);
            return;
        }

        try {
            $this->resque->getStatusFactory()->forJob($job)->update(Status::STATUS_COMPLETE);
        } catch (JobIdException $e) {
            $this->logger->warning('Could not mark job complete: no ID in payload - {exception}', array('exception' => $e));
        }

        $payload = $job->getPayload();

        $this->logger->notice('Finished job {queue}/{class} (ID: {id})', array(
            'queue' => $job->getQueue(),
            'class' => get_class($job),
            'id'    => isset($payload['id']) ? $payload['id'] : 'unknown'
        ));

        $this->logger->debug('Done with {job}', array('job' => $job));
    }
272706
protected function raiseFailedJobEvent($connection, Job $job)
    {
        if (isset($this->events)) {
            $this->events->dispatch('nova.queue.failed', array($connection, $job));
        }
    }
888034
protected function raiseBeforeJobEvent( $connection, Job $job )
	{
		$data = json_decode( $job->getRawBody(), true );
		Framework::hooks()->trigger( 'queue.job.processing', compact( 'connection', 'job', 'data' ) );
	}
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);
    }
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
            ));
        }
    }
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;
        }
    }
283820
public function push( $job, $data = '', $queue = null )
	{
		$queueJob = $this->resolveJob( $this->createPayload( $job, $data, $queue ) );

		try
		{
			$this->raiseBeforeJobEvent( $queueJob );

			$queueJob->fire();

			$this->raiseAfterJobEvent( $queueJob );
		}
		catch ( Exception $e )
		{
			$this->raiseExceptionOccurredJobEvent( $queueJob, $e );

			$this->handleFailedJob( $queueJob );

			throw $e;
		}
		catch ( Throwable $e )
		{
			$this->raiseExceptionOccurredJobEvent( $queueJob, $e );

			$this->handleFailedJob( $queueJob );

			throw $e;
		}

		return 0;
	}
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()
            ));
        }
    }