Skip to content

Commit

Permalink
Fix: minor fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritdead committed May 20, 2017
1 parent 2c53897 commit d23e4e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
16 changes: 10 additions & 6 deletions components/workers/ResqueWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,19 @@ public function startup()
*
* @param Resque $resqueInst
* @param string $workerId The ID of the worker.
* @return boolean|ResqueWorkerBase|ResqueWorkerInterface Instance of the worker. False if the worker does not exist.
* @return null|ResqueWorkerBase|ResqueWorkerInterface Instance of the worker. False if the worker does not exist.
*/
public static function find($resqueInst, $workerId)
{
if (!self::exists($resqueInst, $workerId) || false === strpos($workerId, ":")) {
return false;
return null;
}


$worker = new self($resqueInst);
$worker->restore($workerId);
return $worker;
if($worker->restore($workerId)) {
return $worker;
}
return null;
}

/**
Expand All @@ -206,7 +207,10 @@ public static function all($resqueInst)
$workers = [];
if (is_array($workersRaw) && count($workersRaw) > 0) {
foreach ($workersRaw as $workerId) {
$workers[] = self::find($resqueInst, $workerId);
$worker = self::find($resqueInst, $workerId);
if(isset($worker)) {
$workers[] = $worker;
}
}
}
return $workers;
Expand Down
8 changes: 8 additions & 0 deletions components/workers/base/ResqueWorkerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ public function __construct(Resque $resqueInst, $queues = '*')
/**
* Method for regenerate worker from the current ID saved in the redis and the instance in the server
* @param $workerInstance
* @return boolean // Success or Fail
*/
public function restore($workerInstance)
{
list($hostname, $pid, $queues) = explode(':', $workerInstance, 3);
if (!is_array($queues)) {
$queues = explode(',', $queues);
}

$this->queues = $queues;
$this->pid = $pid;
$this->id = $workerInstance; //regenerate worker
Expand All @@ -135,6 +137,12 @@ public function restore($workerInstance)
$data = json_decode($data, true);
$this->currentJob = new ResqueJobBase($this->resqueInstance, $data['queue'], $data['payload'], true);
}
$workerPids = self::workerPids();
if (!in_array($pid, $workerPids)) {
$this->unregisterWorker();
return false;
}
return true;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion plugins/schedule/workers/ResqueWorkerScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public static function all($resqueInst)
$workers = [];
if (is_array($workersRaw) && count($workersRaw) > 0) {
foreach ($workersRaw as $workerId) {
$workers[] = self::find($resqueInst, $workerId);
$worker = self::find($resqueInst, $workerId);
if(isset($worker)) {
$workers[] = $worker;
}
}
}
return $workers;
Expand Down

0 comments on commit d23e4e7

Please sign in to comment.