Skip to content

Commit

Permalink
Merge branch 'Broutard-patch-1' of https://github.com/Broutard/framework
Browse files Browse the repository at this point in the history
 into Broutard-Broutard-patch-1
  • Loading branch information
taylorotwell committed May 8, 2017
2 parents cef1055 + 11b921b commit 972a2e1
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 972a2e1

Please sign in to comment.