Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
use Exception;
use Throwable;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\DetectsLostConnections;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Illuminate\Contracts\Cache\Repository as CacheContract;

class Worker
{
use DetectsLostConnections;

/**
* The queue manager instance.
*
Expand Down Expand Up @@ -46,6 +49,13 @@ class Worker
*/
public $shouldQuit = false;

/**
* Indicates if the worker should stop.
*
* @var bool
*/
public $shouldStop = false;

/**
* Indicates if the worker is paused.
*
Expand Down Expand Up @@ -195,6 +205,8 @@ protected function stopIfNecessary(WorkerOptions $options, $lastRestart)
$this->stop(12);
} elseif ($this->queueShouldRestart($lastRestart)) {
$this->stop();
} elseif ($this->shouldStop) {
$this->stop(1);
}
}

Expand Down Expand Up @@ -239,6 +251,8 @@ protected function getNextJob($connection, $queue)
}
} catch (Exception $e) {
$this->exceptions->report($e);

$this->handleException($e);
} catch (Throwable $e) {
$this->exceptions->report(new FatalThrowableError($e));
}
Expand All @@ -258,11 +272,26 @@ protected function runJob($job, $connectionName, WorkerOptions $options)
return $this->process($connectionName, $job, $options);
} catch (Exception $e) {
$this->exceptions->report($e);

$this->handleException($e);
} catch (Throwable $e) {
$this->exceptions->report(new FatalThrowableError($e));
}
}

/**
* Handle a serious job exception.
*
* @param \Exception $e
* @return void
*/
protected function handleException($e)
{
if ($this->causedByLostConnection($e)) {
$this->shouldStop = true;
}
}

/**
* Process the given job from the queue.
*
Expand Down