@@ -187,6 +187,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
187187 pcntl_signal_dispatch ();
188188 }
189189
190+ $ ready_statuses = array (Status::STATUS_WAITING , Status::STATUS_RUNNING );
191+
190192 while (true ) {
191193 if ($ this ->shutdown ) {
192194 break ;
@@ -208,7 +210,9 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
208210 $ job = false ;
209211 if (!$ this ->paused ) {
210212 if ($ blocking === true ) {
211- $ this ->logger ->log (LogLevel::INFO , 'Starting blocking with timeout of {interval} ' , array ('interval ' => $ interval ));
213+ $ context = array ('interval ' => $ interval );
214+ $ message = 'Starting blocking with timeout of {interval} ' ;
215+ $ this ->logger ->log (LogLevel::INFO , $ message , $ context );
212216 $ this ->updateProcLine ('Waiting with blocking timeout ' . $ interval );
213217 } else {
214218 $ this ->updateProcLine ('Waiting with interval ' . $ interval );
@@ -225,7 +229,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
225229
226230 if ($ blocking === false ) {
227231 // If no job was found, we sleep for $interval before continuing and checking again
228- $ this ->logger ->log (LogLevel::INFO , 'Sleeping for {interval} ' , array ('interval ' => $ interval ));
232+ $ context = array ('interval ' => $ interval );
233+ $ this ->logger ->log (LogLevel::INFO , 'Sleeping for {interval} ' , $ context );
229234 if ($ this ->paused ) {
230235 $ this ->updateProcLine ('Paused ' );
231236 } else {
@@ -238,7 +243,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
238243 continue ;
239244 }
240245
241- $ this ->logger ->log (LogLevel::NOTICE , 'Starting work on {job} ' , array ('job ' => $ job ));
246+ $ context = array ('job ' => $ job );
247+ $ this ->logger ->log (LogLevel::NOTICE , 'Starting work on {job} ' , $ context );
242248 Event::trigger ('beforeFork ' , $ job );
243249 $ this ->workingOn ($ job );
244250
@@ -288,7 +294,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
288294 'Job exited with exit code ' . $ exitStatus
289295 ));
290296 } else {
291- if (in_array ($ job ->getStatus (), array (Status:: STATUS_WAITING , Status:: STATUS_RUNNING ) )) {
297+ if (in_array ($ job ->getStatus (), $ ready_statuses )) {
292298 $ job ->updateStatus (Status::STATUS_COMPLETE );
293299 $ this ->logger ->log (LogLevel::INFO , 'done ' . $ job );
294300 }
@@ -314,11 +320,13 @@ public function perform(JobHandler $job)
314320 Event::trigger ('afterFork ' , $ job );
315321 $ result = $ job ->perform ();
316322 } catch (Exception $ e ) {
317- $ this ->logger ->log (LogLevel::CRITICAL , '{job} has failed {exception} ' , array ('job ' => $ job , 'exception ' => $ e ));
323+ $ context = array ('job ' => $ job , 'exception ' => $ e );
324+ $ this ->logger ->log (LogLevel::CRITICAL , '{job} has failed {exception} ' , $ context );
318325 $ job ->fail ($ e );
319326 return ;
320327 } catch (Error $ e ) {
321- $ this ->logger ->log (LogLevel::CRITICAL , '{job} has failed {exception} ' , array ('job ' => $ job , 'exception ' => $ e ));
328+ $ context = array ('job ' => $ job , 'exception ' => $ e );
329+ $ this ->logger ->log (LogLevel::CRITICAL , '{job} has failed {exception} ' , $ context );
322330 $ job ->fail ($ e );
323331 return ;
324332 }
@@ -346,21 +354,25 @@ public function reserve($blocking = false, $timeout = null)
346354
347355 if ($ blocking === true ) {
348356 if (empty ($ queues )) {
349- $ this ->logger ->log (LogLevel::INFO , 'No queue was found, sleeping for {interval} ' , array ('interval ' => $ timeout ));
357+ $ context = array ('interval ' => $ timeout );
358+ $ this ->logger ->log (LogLevel::INFO , 'No queue was found, sleeping for {interval} ' , $ context );
350359 usleep ($ timeout * 1000000 );
351360 return false ;
352361 }
353362 $ job = JobHandler::reserveBlocking ($ queues , $ timeout );
354363 if ($ job ) {
355- $ this ->logger ->log (LogLevel::INFO , 'Found job on {queue} ' , array ('queue ' => $ job ->queue ));
364+ $ context = array ('queue ' => $ job ->queue );
365+ $ this ->logger ->log (LogLevel::INFO , 'Found job on {queue} ' , $ context );
356366 return $ job ;
357367 }
358368 } else {
359369 foreach ($ queues as $ queue ) {
360- $ this ->logger ->log (LogLevel::INFO , 'Checking {queue} for jobs ' , array ('queue ' => $ queue ));
370+ $ context = array ('queue ' => $ queue );
371+ $ this ->logger ->log (LogLevel::INFO , 'Checking {queue} for jobs ' , $ context );
361372 $ job = JobHandler::reserve ($ queue );
362373 if ($ job ) {
363- $ this ->logger ->log (LogLevel::INFO , 'Found job on {queue} ' , array ('queue ' => $ job ->queue ));
374+ $ context = array ('queue ' => $ job ->queue );
375+ $ this ->logger ->log (LogLevel::INFO , 'Found job on {queue} ' , $ context );
364376 return $ job ;
365377 }
366378 }
@@ -411,7 +423,8 @@ private function startup()
411423 */
412424 private function updateProcLine ($ status )
413425 {
414- $ processTitle = static ::$ processPrefix . '- ' . Resque::VERSION . ' ( ' . implode (', ' , $ this ->queues ) . '): ' . $ status ;
426+ $ processTitle = static ::$ processPrefix . '- ' . Resque::VERSION ;
427+ $ processTitle .= ' ( ' . implode (', ' , $ this ->queues ) . '): ' . $ status ;
415428 if (function_exists ('cli_set_process_title ' ) && PHP_OS !== 'Darwin ' ) {
416429 cli_set_process_title ($ processTitle );
417430 } elseif (function_exists ('setproctitle ' )) {
@@ -500,13 +513,16 @@ public function killChild()
500513 return ;
501514 }
502515
503- $ this ->logger ->log (LogLevel::INFO , 'Killing child at {child} ' , array ('child ' => $ this ->child ));
516+ $ context = array ('child ' => $ this ->child );
517+ $ this ->logger ->log (LogLevel::INFO , 'Killing child at {child} ' , $ context );
504518 if (exec ('ps -o pid,s -p ' . $ this ->child , $ output , $ returnCode ) && $ returnCode != 1 ) {
505- $ this ->logger ->log (LogLevel::DEBUG , 'Child {child} found, killing. ' , array ('child ' => $ this ->child ));
519+ $ context = array ('child ' => $ this ->child );
520+ $ this ->logger ->log (LogLevel::DEBUG , 'Child {child} found, killing. ' , $ context );
506521 posix_kill ($ this ->child , SIGKILL );
507522 $ this ->child = null ;
508523 } else {
509- $ this ->logger ->log (LogLevel::INFO , 'Child {child} not found, restarting. ' , array ('child ' => $ this ->child ));
524+ $ context = array ('child ' => $ this ->child );
525+ $ this ->logger ->log (LogLevel::INFO , 'Child {child} not found, restarting. ' , $ context );
510526 $ this ->shutdown ();
511527 }
512528 }
@@ -529,7 +545,8 @@ public function pruneDeadWorkers()
529545 if ($ host != $ this ->hostname || in_array ($ pid , $ workerPids ) || $ pid == getmypid ()) {
530546 continue ;
531547 }
532- $ this ->logger ->log (LogLevel::INFO , 'Pruning dead worker: {worker} ' , array ('worker ' => (string )$ worker ));
548+ $ context = array ('worker ' => (string )$ worker );
549+ $ this ->logger ->log (LogLevel::INFO , 'Pruning dead worker: {worker} ' , $ context );
533550 $ worker ->unregisterWorker ();
534551 }
535552 }
0 commit comments