diff --git a/src/Illuminate/Queue/Events/WorkerStopping.php b/src/Illuminate/Queue/Events/WorkerStopping.php index 6d49bb2092ac..8ca84cf3ba48 100644 --- a/src/Illuminate/Queue/Events/WorkerStopping.php +++ b/src/Illuminate/Queue/Events/WorkerStopping.php @@ -2,23 +2,34 @@ namespace Illuminate\Queue\Events; +use Illuminate\Queue\WorkerOptions; + class WorkerStopping { /** - * The exit status. + * The worker exit status. * * @var int */ public $status; + /** + * The worker options. + * + * @var \Illuminate\Queue\WorkerOptions|null + */ + public $workerOptions; + /** * Create a new event instance. * * @param int $status + * @param \Illuminate\Queue\WorkerOptions|null $workerOptions * @return void */ - public function __construct($status = 0) + public function __construct($status = 0, $workerOptions = null) { $this->status = $status; + $this->workerOptions = $workerOptions; } } diff --git a/src/Illuminate/Queue/Worker.php b/src/Illuminate/Queue/Worker.php index 039cbebb309e..8be7a10f2a14 100644 --- a/src/Illuminate/Queue/Worker.php +++ b/src/Illuminate/Queue/Worker.php @@ -143,7 +143,7 @@ public function daemon($connectionName, $queue, WorkerOptions $options) $status = $this->pauseWorker($options, $lastRestart); if (! is_null($status)) { - return $this->stop($status); + return $this->stop($status, $options); } continue; @@ -191,7 +191,7 @@ public function daemon($connectionName, $queue, WorkerOptions $options) ); if (! is_null($status)) { - return $this->stop($status); + return $this->stop($status, $options); } } } @@ -223,7 +223,7 @@ protected function registerTimeoutHandler($job, WorkerOptions $options) ); } - $this->kill(static::EXIT_ERROR); + $this->kill(static::EXIT_ERROR, $options); }); pcntl_alarm( @@ -579,7 +579,7 @@ protected function markJobAsFailedIfItShouldFailOnTimeout($connectionName, $job, */ protected function failJob($job, Throwable $e) { - return $job->fail($e); + $job->fail($e); } /** @@ -676,21 +676,10 @@ protected function listenForSignals() { pcntl_async_signals(true); - pcntl_signal(SIGQUIT, function () { - $this->shouldQuit = true; - }); - - pcntl_signal(SIGTERM, function () { - $this->shouldQuit = true; - }); - - pcntl_signal(SIGUSR2, function () { - $this->paused = true; - }); - - pcntl_signal(SIGCONT, function () { - $this->paused = false; - }); + pcntl_signal(SIGQUIT, fn () => $this->shouldQuit = true); + pcntl_signal(SIGTERM, fn () => $this->shouldQuit = true); + pcntl_signal(SIGUSR2, fn () => $this->paused = true); + pcntl_signal(SIGCONT, fn () => $this->paused = false); } /** @@ -718,11 +707,12 @@ public function memoryExceeded($memoryLimit) * Stop listening and bail out of the script. * * @param int $status + * @param WorkerOptions|null $options * @return int */ - public function stop($status = 0) + public function stop($status = 0, $options = null) { - $this->events->dispatch(new WorkerStopping($status)); + $this->events->dispatch(new WorkerStopping($status, $options)); return $status; } @@ -731,11 +721,12 @@ public function stop($status = 0) * Kill the process. * * @param int $status + * @param \Illuminate\Queue\WorkerOptions|null $options * @return never */ - public function kill($status = 0) + public function kill($status = 0, $options = null) { - $this->events->dispatch(new WorkerStopping($status)); + $this->events->dispatch(new WorkerStopping($status, $options)); if (extension_loaded('posix')) { posix_kill(getmypid(), SIGKILL); @@ -817,7 +808,7 @@ public static function popUsing($workerName, $callback) /** * Get the queue manager instance. * - * @return \Illuminate\Queue\QueueManager + * @return \Illuminate\Contracts\Queue\Factory */ public function getManager() { diff --git a/tests/Queue/QueueWorkerTest.php b/tests/Queue/QueueWorkerTest.php index d600e5776d6e..4e66ecd72aed 100755 --- a/tests/Queue/QueueWorkerTest.php +++ b/tests/Queue/QueueWorkerTest.php @@ -40,9 +40,9 @@ protected function tearDown(): void { parent::tearDown(); - Carbon::setTestNow(null); + Carbon::setTestNow(); - Container::setInstance(null); + Container::setInstance(); } public function testJobCanBeFired() @@ -411,7 +411,7 @@ public function sleep($seconds) $this->sleptFor = $seconds; } - public function stop($status = 0) + public function stop($status = 0, $options = null) { return $status; }