Skip to content

Commit 37e148b

Browse files
author
Chris Boulton
committed
Merge pull request #42 from salimane/upstream
Avoid working with dirty worker ids
2 parents 6165de4 + 5b24b47 commit 37e148b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/Resque/Worker.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Resque_Worker
5353
* @var Resque_Job Current job, if any, being processed by this worker.
5454
*/
5555
private $currentJob = null;
56-
56+
5757
/**
5858
* @var int Process ID of child worker processes.
5959
*/
@@ -95,7 +95,7 @@ public static function exists($workerId)
9595
*/
9696
public static function find($workerId)
9797
{
98-
if(!self::exists($workerId)) {
98+
if(!self::exists($workerId) || false === strpos($workerId, ":")) {
9999
return false;
100100
}
101101

@@ -447,12 +447,14 @@ public function pruneDeadWorkers()
447447
$workerPids = $this->workerPids();
448448
$workers = self::all();
449449
foreach($workers as $worker) {
450-
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
451-
if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
452-
continue;
453-
}
454-
$this->log('Pruning dead worker: ' . (string)$worker, self::LOG_VERBOSE);
455-
$worker->unregisterWorker();
450+
if (is_object($worker)) {
451+
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
452+
if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
453+
continue;
454+
}
455+
$this->log('Pruning dead worker: ' . (string)$worker, self::LOG_VERBOSE);
456+
$worker->unregisterWorker();
457+
}
456458
}
457459
}
458460

0 commit comments

Comments
 (0)