From ec2ff9c88315b840a9f10557ebc1d233dbf2634d Mon Sep 17 00:00:00 2001 From: Broutard Date: Fri, 5 May 2017 23:42:00 +0200 Subject: [PATCH 1/5] Update Worker.php --- src/Illuminate/Queue/Worker.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 782a863c5c9f..5e096805cd68 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -8,9 +8,13 @@ use Illuminate\Contracts\Debug\ExceptionHandler; use Symfony\Component\Debug\Exception\FatalThrowableError; use Illuminate\Contracts\Cache\Repository as CacheContract; +use Illuminate\Database\QueryException; +use Illuminate\Database\DetectsLostConnections; class Worker { + use DetectsLostConnections; + /** * The queue manager instance. * @@ -239,6 +243,8 @@ protected function getNextJob($connection, $queue) } } catch (Exception $e) { $this->exceptions->report($e); + + $this->handleDatabaseException($e); } catch (Throwable $e) { $this->exceptions->report(new FatalThrowableError($e)); } @@ -258,11 +264,28 @@ protected function runJob($job, $connectionName, WorkerOptions $options) return $this->process($connectionName, $job, $options); } catch (Exception $e) { $this->exceptions->report($e); + + $this->handleDatabaseException($e); } catch (Throwable $e) { $this->exceptions->report(new FatalThrowableError($e)); } } + /** + * Handle a database exception. + * + * @param \Exception $e + * @return void + */ + protected function handleDatabaseException($e) { + if ($e instanceof QueryException && $this->causedByLostConnection($e->getPrevious())) { + $this->stop(1); + } + elseif ($this->causedByLostConnection($e)) { + $this->stop(1); + } + } + /** * Process the given job from the queue. * From ef44535e3a26af29b2cbe29577df6af240aa6b20 Mon Sep 17 00:00:00 2001 From: Broutard Date: Fri, 5 May 2017 23:49:12 +0200 Subject: [PATCH 2/5] Update Worker.php fix: styleCI --- src/Illuminate/Queue/Worker.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 5e096805cd68..26ae7b8439f5 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -4,12 +4,12 @@ use Exception; use Throwable; +use Illuminate\Database\QueryException; 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; -use Illuminate\Database\QueryException; -use Illuminate\Database\DetectsLostConnections; class Worker { @@ -277,11 +277,11 @@ protected function runJob($job, $connectionName, WorkerOptions $options) * @param \Exception $e * @return void */ - protected function handleDatabaseException($e) { + protected function handleDatabaseException($e) + { if ($e instanceof QueryException && $this->causedByLostConnection($e->getPrevious())) { $this->stop(1); - } - elseif ($this->causedByLostConnection($e)) { + } elseif ($this->causedByLostConnection($e)) { $this->stop(1); } } From 96b465ea4953c6cac328bf7d34547906a3e25fc9 Mon Sep 17 00:00:00 2001 From: Broutard Date: Fri, 5 May 2017 23:50:16 +0200 Subject: [PATCH 3/5] Update Worker.php fix spaces --- src/Illuminate/Queue/Worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 26ae7b8439f5..6a918cd8f3ba 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -277,7 +277,7 @@ protected function runJob($job, $connectionName, WorkerOptions $options) * @param \Exception $e * @return void */ - protected function handleDatabaseException($e) + protected function handleDatabaseException($e) { if ($e instanceof QueryException && $this->causedByLostConnection($e->getPrevious())) { $this->stop(1); From f3c59b1c2e429d9e31c31c885e563c49b8e32401 Mon Sep 17 00:00:00 2001 From: Broutard Date: Sat, 6 May 2017 00:24:20 +0200 Subject: [PATCH 4/5] Update Worker.php refacto: add a $shouldStop property to force stopIfNecessary() --- src/Illuminate/Queue/Worker.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 6a918cd8f3ba..5bcde67faf6e 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -4,12 +4,12 @@ use Exception; use Throwable; -use Illuminate\Database\QueryException; 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; +use Illuminate\Database\QueryException; class Worker { @@ -50,6 +50,13 @@ class Worker */ public $shouldQuit = false; + /** + * Indicates if the worker should stop. + * + * @var bool + */ + public $shouldStop = false; + /** * Indicates if the worker is paused. * @@ -199,6 +206,8 @@ protected function stopIfNecessary(WorkerOptions $options, $lastRestart) $this->stop(12); } elseif ($this->queueShouldRestart($lastRestart)) { $this->stop(); + } elseif ($this->shouldStop) { + $this->stop(1); } } @@ -244,7 +253,7 @@ protected function getNextJob($connection, $queue) } catch (Exception $e) { $this->exceptions->report($e); - $this->handleDatabaseException($e); + $this->handleException($e); } catch (Throwable $e) { $this->exceptions->report(new FatalThrowableError($e)); } @@ -265,24 +274,22 @@ protected function runJob($job, $connectionName, WorkerOptions $options) } catch (Exception $e) { $this->exceptions->report($e); - $this->handleDatabaseException($e); + $this->handleException($e); } catch (Throwable $e) { $this->exceptions->report(new FatalThrowableError($e)); } } /** - * Handle a database exception. + * Handle a serious job exception. * * @param \Exception $e * @return void */ - protected function handleDatabaseException($e) + protected function handleException($e) { - if ($e instanceof QueryException && $this->causedByLostConnection($e->getPrevious())) { - $this->stop(1); - } elseif ($this->causedByLostConnection($e)) { - $this->stop(1); + if ($this->causedByLostConnection($e)) { + $this->shouldStop = true; } } From 11b921bef978c13bf94405335b91b1013a70ea09 Mon Sep 17 00:00:00 2001 From: Broutard Date: Sat, 6 May 2017 00:25:25 +0200 Subject: [PATCH 5/5] Update Worker.php fix: remove useless use --- src/Illuminate/Queue/Worker.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 5bcde67faf6e..37025d7784c8 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -9,7 +9,6 @@ use Illuminate\Contracts\Debug\ExceptionHandler; use Symfony\Component\Debug\Exception\FatalThrowableError; use Illuminate\Contracts\Cache\Repository as CacheContract; -use Illuminate\Database\QueryException; class Worker {