Skip to content

Commit f620279

Browse files
committed
Fix codestyle issues related to too long lines
1 parent daa3399 commit f620279

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

lib/Resque/Job.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public function updateStatus($status, $result = null)
139139
/**
140140
* Return the status of the current job.
141141
*
142-
* @return int|null The status of the job as one of the Resque_Job_Status constants or null if job is not being tracked.
142+
* @return int|null The status of the job as one of the Resque_Job_Status constants
143+
* or null if job is not being tracked.
143144
*/
144145
public function getStatus()
145146
{
@@ -261,7 +262,14 @@ public function recreate()
261262
}
262263
}
263264

264-
return self::create($this->queue, $this->payload['class'], $this->getArguments(), $monitor, null, $this->getPrefix());
265+
return self::create(
266+
$this->queue,
267+
$this->payload['class'],
268+
$this->getArguments(),
269+
$monitor,
270+
null,
271+
$this->getPrefix()
272+
);
265273
}
266274

267275
/**

lib/Resque/Worker.php

+32-15
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
171171
pcntl_signal_dispatch();
172172
}
173173

174+
$ready_statuses = array(Resque_Job_Status::STATUS_WAITING, Resque_Job_Status::STATUS_RUNNING);
175+
174176
while (true) {
175177
if ($this->shutdown) {
176178
break;
@@ -192,7 +194,9 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
192194
$job = false;
193195
if (!$this->paused) {
194196
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);
196200
$this->updateProcLine('Waiting with blocking timeout ' . $interval);
197201
} else {
198202
$this->updateProcLine('Waiting with interval ' . $interval);
@@ -209,7 +213,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
209213

210214
if ($blocking === false) {
211215
// 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);
213218
if ($this->paused) {
214219
$this->updateProcLine('Paused');
215220
} else {
@@ -222,7 +227,8 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
222227
continue;
223228
}
224229

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);
226232
Resque_Event::trigger('beforeFork', $job);
227233
$this->workingOn($job);
228234

@@ -272,7 +278,7 @@ public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
272278
'Job exited with exit code ' . $exitStatus
273279
));
274280
} 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)) {
276282
$job->updateStatus(Resque_Job_Status::STATUS_COMPLETE);
277283
$this->logger->log(Psr\Log\LogLevel::INFO, 'done ' . $job);
278284
}
@@ -298,11 +304,13 @@ public function perform(Resque_Job $job)
298304
Resque_Event::trigger('afterFork', $job);
299305
$result = $job->perform();
300306
} 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);
302309
$job->fail($e);
303310
return;
304311
} 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);
306314
$job->fail($e);
307315
return;
308316
}
@@ -330,21 +338,25 @@ public function reserve($blocking = false, $timeout = null)
330338

331339
if ($blocking === true) {
332340
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);
334343
usleep($timeout * 1000000);
335344
return false;
336345
}
337346
$job = Resque_Job::reserveBlocking($queues, $timeout);
338347
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);
340350
return $job;
341351
}
342352
} else {
343353
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);
345356
$job = Resque_Job::reserve($queue);
346357
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);
348360
return $job;
349361
}
350362
}
@@ -395,7 +407,8 @@ private function startup()
395407
*/
396408
private function updateProcLine($status)
397409
{
398-
$processTitle = static::$processPrefix . '-' . Resque::VERSION . ' (' . implode(',', $this->queues) . '): ' . $status;
410+
$processTitle = static::$processPrefix . '-' . Resque::VERSION;
411+
$processTitle .= ' (' . implode(',', $this->queues) . '): ' . $status;
399412
if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
400413
cli_set_process_title($processTitle);
401414
} elseif (function_exists('setproctitle')) {
@@ -484,13 +497,16 @@ public function killChild()
484497
return;
485498
}
486499

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);
488502
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);
490505
posix_kill($this->child, SIGKILL);
491506
$this->child = null;
492507
} 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);
494510
$this->shutdown();
495511
}
496512
}
@@ -513,7 +529,8 @@ public function pruneDeadWorkers()
513529
if ($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
514530
continue;
515531
}
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);
517534
$worker->unregisterWorker();
518535
}
519536
}

0 commit comments

Comments
 (0)