Skip to content

Commit aa523db

Browse files
authored
Fix codestyle issues related to too long lines (#54)
1 parent 6334006 commit aa523db

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

lib/FailureHandler.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class FailureHandler
2525
*
2626
* @param object $payload The contents of the job that has just failed.
2727
* @param \Exception $exception The exception generated when the job failed to run.
28-
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker that was running this job when it failed.
28+
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
29+
* that was running this job when it failed.
2930
* @param string $queue The name of the queue that this job was fetched from.
3031
*/
3132
public static function create($payload, Exception $exception, ResqueWorker $worker, $queue)
@@ -39,7 +40,8 @@ public static function create($payload, Exception $exception, ResqueWorker $work
3940
*
4041
* @param object $payload The contents of the job that has just failed.
4142
* @param \Error $exception The PHP 7 error generated when the job failed to run.
42-
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker that was running this job when it failed.
43+
* @param \Resque\Worker\ResqueWorker $worker Instance of Resque\Worker\ResqueWorker
44+
* that was running this job when it failed.
4345
* @param string $queue The name of the queue that this job was fetched from.
4446
*/
4547
public static function createFromError($payload, Error $exception, ResqueWorker $worker, $queue)

lib/JobHandler.php

+12-3
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public function updateStatus($status, $result = null)
148148
/**
149149
* Return the status of the current job.
150150
*
151-
* @return int|null The status of the job as one of the Resque\Job\Status constants or null if job is not being tracked.
151+
* @return int|null The status of the job as one of the Resque\Job\Status constants
152+
* or null if job is not being tracked.
152153
*/
153154
public function getStatus()
154155
{
@@ -195,7 +196,8 @@ public function getInstance()
195196
* associated with the job with the supplied arguments.
196197
*
197198
* @return bool
198-
* @throws Resque\Exceptions\ResqueException When the job's class could not be found or it does not contain a perform method.
199+
* @throws Resque\Exceptions\ResqueException When the job's class could not be found
200+
* or it does not contain a perform method.
199201
*/
200202
public function perform()
201203
{
@@ -269,7 +271,14 @@ public function recreate()
269271
}
270272
}
271273

272-
return self::create($this->queue, $this->payload['class'], $this->getArguments(), $monitor, null, $this->getPrefix());
274+
return self::create(
275+
$this->queue,
276+
$this->payload['class'],
277+
$this->getArguments(),
278+
$monitor,
279+
null,
280+
$this->getPrefix()
281+
);
273282
}
274283

275284
/**

lib/Worker/ResqueWorker.php

+32-15
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)