Skip to content

Commit

Permalink
avoid working with dirty worker ids
Browse files Browse the repository at this point in the history
  • Loading branch information
salimane committed Feb 2, 2012
1 parent 4700375 commit 5b24b47
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/Resque/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Resque_Worker
* @var Resque_Job Current job, if any, being processed by this worker.
*/
private $currentJob = null;

/**
* @var int Process ID of child worker processes.
*/
Expand Down Expand Up @@ -95,7 +95,7 @@ public static function exists($workerId)
*/
public static function find($workerId)
{
if(!self::exists($workerId)) {
if(!self::exists($workerId) || false === strpos($workerId, ":")) {
return false;
}

Expand Down Expand Up @@ -447,12 +447,14 @@ public function pruneDeadWorkers()
$workerPids = $this->workerPids();
$workers = self::all();
foreach($workers as $worker) {
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
continue;
}
$this->log('Pruning dead worker: ' . (string)$worker, self::LOG_VERBOSE);
$worker->unregisterWorker();
if (is_object($worker)) {
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
continue;
}
$this->log('Pruning dead worker: ' . (string)$worker, self::LOG_VERBOSE);
$worker->unregisterWorker();
}
}
}

Expand Down

0 comments on commit 5b24b47

Please sign in to comment.