@@ -171,6 +171,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
171
171
pcntl_signal_dispatch ();
172
172
}
173
173
174
+ $ ready_statuses = array (Resque_Job_Status::STATUS_WAITING , Resque_Job_Status::STATUS_RUNNING );
175
+
174
176
while (true ) {
175
177
if ($ this ->shutdown ) {
176
178
break ;
@@ -192,7 +194,9 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
192
194
$ job = false ;
193
195
if (!$ this ->paused ) {
194
196
if ($ blocking === true ) {
195
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Starting blocking with timeout of {interval} ' , array ('interval ' => $ interval ));
197
+ $ context = array ('interval ' => $ interval );
198
+ $ message = 'Starting blocking with timeout of {interval} ' ;
199
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , $ message , $ context );
196
200
$ this ->updateProcLine ('Waiting with blocking timeout ' . $ interval );
197
201
} else {
198
202
$ this ->updateProcLine ('Waiting with interval ' . $ interval );
@@ -209,7 +213,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
209
213
210
214
if ($ blocking === false ) {
211
215
// If no job was found, we sleep for $interval before continuing and checking again
212
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Sleeping for {interval} ' , array ('interval ' => $ interval ));
216
+ $ context = array ('interval ' => $ interval );
217
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Sleeping for {interval} ' , $ context );
213
218
if ($ this ->paused ) {
214
219
$ this ->updateProcLine ('Paused ' );
215
220
} else {
@@ -222,7 +227,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
222
227
continue ;
223
228
}
224
229
225
- $ this ->logger ->log (Psr \Log \LogLevel::NOTICE , 'Starting work on {job} ' , array ('job ' => $ job ));
230
+ $ context = array ('job ' => $ job );
231
+ $ this ->logger ->log (Psr \Log \LogLevel::NOTICE , 'Starting work on {job} ' , $ context );
226
232
Resque_Event::trigger ('beforeFork ' , $ job );
227
233
$ this ->workingOn ($ job );
228
234
@@ -272,7 +278,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
272
278
'Job exited with exit code ' . $ exitStatus
273
279
));
274
280
} else {
275
- if (in_array ($ job ->getStatus (), array (Resque_Job_Status:: STATUS_WAITING , Resque_Job_Status:: STATUS_RUNNING ) )) {
281
+ if (in_array ($ job ->getStatus (), $ ready_statuses )) {
276
282
$ job ->updateStatus (Resque_Job_Status::STATUS_COMPLETE );
277
283
$ this ->logger ->log (Psr \Log \LogLevel::INFO , 'done ' . $ job );
278
284
}
@@ -298,11 +304,13 @@ public function perform(Resque_Job $job)
298
304
Resque_Event::trigger ('afterFork ' , $ job );
299
305
$ result = $ job ->perform ();
300
306
} catch (Exception $ e ) {
301
- $ this ->logger ->log (Psr \Log \LogLevel::CRITICAL , '{job} has failed {exception} ' , array ('job ' => $ job , 'exception ' => $ e ));
307
+ $ context = array ('job ' => $ job , 'exception ' => $ e );
308
+ $ this ->logger ->log (Psr \Log \LogLevel::CRITICAL , '{job} has failed {exception} ' , $ context );
302
309
$ job ->fail ($ e );
303
310
return ;
304
311
} catch (Error $ e ) {
305
- $ this ->logger ->log (Psr \Log \LogLevel::CRITICAL , '{job} has failed {exception} ' , array ('job ' => $ job , 'exception ' => $ e ));
312
+ $ context = array ('job ' => $ job , 'exception ' => $ e );
313
+ $ this ->logger ->log (Psr \Log \LogLevel::CRITICAL , '{job} has failed {exception} ' , $ context );
306
314
$ job ->fail ($ e );
307
315
return ;
308
316
}
@@ -330,21 +338,25 @@ public function reserve($blocking = false, $timeout = null)
330
338
331
339
if ($ blocking === true ) {
332
340
if (empty ($ queues )) {
333
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'No queue was found, sleeping for {interval} ' , array ('interval ' => $ timeout ));
341
+ $ context = array ('interval ' => $ timeout );
342
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'No queue was found, sleeping for {interval} ' , $ context );
334
343
usleep ($ timeout * 1000000 );
335
344
return false ;
336
345
}
337
346
$ job = Resque_Job::reserveBlocking ($ queues , $ timeout );
338
347
if ($ job ) {
339
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Found job on {queue} ' , array ('queue ' => $ job ->queue ));
348
+ $ context = array ('queue ' => $ job ->queue );
349
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Found job on {queue} ' , $ context );
340
350
return $ job ;
341
351
}
342
352
} else {
343
353
foreach ($ queues as $ queue ) {
344
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Checking {queue} for jobs ' , array ('queue ' => $ queue ));
354
+ $ context = array ('queue ' => $ queue );
355
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Checking {queue} for jobs ' , $ context );
345
356
$ job = Resque_Job::reserve ($ queue );
346
357
if ($ job ) {
347
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Found job on {queue} ' , array ('queue ' => $ job ->queue ));
358
+ $ context = array ('queue ' => $ job ->queue );
359
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Found job on {queue} ' , $ context );
348
360
return $ job ;
349
361
}
350
362
}
@@ -395,7 +407,8 @@ private function startup()
395
407
*/
396
408
private function updateProcLine ($ status )
397
409
{
398
- $ processTitle = static ::$ processPrefix . '- ' . Resque::VERSION . ' ( ' . implode (', ' , $ this ->queues ) . '): ' . $ status ;
410
+ $ processTitle = static ::$ processPrefix . '- ' . Resque::VERSION ;
411
+ $ processTitle .= ' ( ' . implode (', ' , $ this ->queues ) . '): ' . $ status ;
399
412
if (function_exists ('cli_set_process_title ' ) && PHP_OS !== 'Darwin ' ) {
400
413
cli_set_process_title ($ processTitle );
401
414
} elseif (function_exists ('setproctitle ' )) {
@@ -484,13 +497,16 @@ public function killChild()
484
497
return ;
485
498
}
486
499
487
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Killing child at {child} ' , array ('child ' => $ this ->child ));
500
+ $ context = array ('child ' => $ this ->child );
501
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Killing child at {child} ' , $ context );
488
502
if (exec ('ps -o pid,s -p ' . $ this ->child , $ output , $ returnCode ) && $ returnCode != 1 ) {
489
- $ this ->logger ->log (Psr \Log \LogLevel::DEBUG , 'Child {child} found, killing. ' , array ('child ' => $ this ->child ));
503
+ $ context = array ('child ' => $ this ->child );
504
+ $ this ->logger ->log (Psr \Log \LogLevel::DEBUG , 'Child {child} found, killing. ' , $ context );
490
505
posix_kill ($ this ->child , SIGKILL );
491
506
$ this ->child = null ;
492
507
} else {
493
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Child {child} not found, restarting. ' , array ('child ' => $ this ->child ));
508
+ $ context = array ('child ' => $ this ->child );
509
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Child {child} not found, restarting. ' , $ context );
494
510
$ this ->shutdown ();
495
511
}
496
512
}
@@ -513,7 +529,8 @@ public function pruneDeadWorkers()
513
529
if ($ host != $ this ->hostname || in_array ($ pid , $ workerPids ) || $ pid == getmypid ()) {
514
530
continue ;
515
531
}
516
- $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Pruning dead worker: {worker} ' , array ('worker ' => (string )$ worker ));
532
+ $ context = array ('worker ' => (string )$ worker );
533
+ $ this ->logger ->log (Psr \Log \LogLevel::INFO , 'Pruning dead worker: {worker} ' , $ context );
517
534
$ worker ->unregisterWorker ();
518
535
}
519
536
}
0 commit comments