@@ -146,8 +146,9 @@ protected function registerTimeoutHandler($job, WorkerOptions $options)
146146 $ this ->kill (1 );
147147 });
148148
149- $ timeout = $ this ->timeoutForJob ($ job , $ options );
150- pcntl_alarm ($ timeout > 0 ? $ timeout + $ options ->sleep : 0 );
149+ pcntl_alarm (
150+ max ($ this ->timeoutForJob ($ job , $ options ), 0 )
151+ );
151152 }
152153 }
153154
@@ -171,11 +172,11 @@ protected function timeoutForJob($job, WorkerOptions $options)
171172 *
172173 * @return bool
173174 */
174- protected function daemonShouldRun (WorkerOptions $ options )
175+ public function daemonShouldRun (WorkerOptions $ options )
175176 {
176177 return ! (($ this ->manager ->isDownForMaintenance () && ! $ options ->force ) ||
177- $ this ->paused ||
178- $ this ->until () = == false );
178+ $ this ->isPaused () ||
179+ $ this ->until () ! == false );
179180 }
180181
181182 /**
@@ -260,11 +261,11 @@ protected function getNextJob($connection, $queue)
260261 } catch (\Exception $ e ) {
261262
262263 $ this ->exceptions ->report ($ e );
264+ $ this ->stopWorkerIfLostConnection ($ e );
263265
264266 } catch (\Throwable $ e ) {
265267
266268 $ this ->exceptions ->report ($ e = new FatalThrowableError ($ e ));
267-
268269 $ this ->stopWorkerIfLostConnection ($ e );
269270 }
270271 }
@@ -417,8 +418,14 @@ protected function handleJobException($connectionName, $job, WorkerOptions $opti
417418 protected function markJobAsFailedIfAlreadyExceedsMaxAttempts ($ connectionName , $ job , $ maxTries )
418419 {
419420 $ maxTries = !is_null ($ job ->maxTries ()) ? $ job ->maxTries () : $ maxTries ;
421+ $ timeoutAt = $ job ->timeout ();
422+
423+ if ($ timeoutAt && (new \DateTimeImmutable )->getTimestamp () <= $ timeoutAt ) {
424+
425+ return ;
426+ }
420427
421- if ($ maxTries === 0 || $ job ->attempts () <= $ maxTries ) {
428+ if (! $ timeoutAt && ( $ maxTries === 0 || $ job ->attempts () <= $ maxTries) ) {
422429
423430 return ;
424431 }
@@ -440,7 +447,12 @@ protected function markJobAsFailedIfAlreadyExceedsMaxAttempts($connectionName, $
440447 */
441448 protected function markJobAsFailedIfWillExceedMaxAttempts ($ connectionName , $ job , $ maxTries , $ e )
442449 {
443- $ maxTries = !is_null ($ job ->maxTries ()) ? $ job ->maxTries () : $ maxTries ;
450+ $ maxTries = ! is_null ($ job ->maxTries ()) ? $ job ->maxTries () : $ maxTries ;
451+
452+ if ($ job ->timeoutAt () && $ job ->timeoutAt () <= (new \DateTimeImmutable )->getTimestamp ()) {
453+
454+ $ this ->failJob ($ connectionName , $ job , $ e );
455+ }
444456
445457 if ($ maxTries > 0 && $ job ->attempts () >= $ maxTries ) {
446458
@@ -606,6 +618,8 @@ public function stop($status = 0)
606618 */
607619 public function kill ($ status = 0 )
608620 {
621+ $ this ->events ->dispatch (EventsList::WORKER_STOPPING , new Event \WorkerStopping );
622+
609623 if (extension_loaded ('posix ' )) {
610624
611625 posix_kill (getmypid (), SIGKILL );
@@ -662,6 +676,14 @@ protected function until()
662676 return $ this ->events ->dispatch (EventsList::LOOPING , new Event \Looping )->isPropagationStopped ();
663677 }
664678
679+ /**
680+ * @return bool
681+ */
682+ public function isPaused ()
683+ {
684+ return $ this ->paused ;
685+ }
686+
665687 /**
666688 * Raise the failed queue job event.
667689 *
0 commit comments