From d23e4e7012b798560bc37ab7336f9f0ba67a0990 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Sat, 20 May 2017 17:22:14 +1000 Subject: [PATCH] Fix: minor fixs --- components/workers/ResqueWorker.php | 16 ++++++++++------ components/workers/base/ResqueWorkerBase.php | 8 ++++++++ .../schedule/workers/ResqueWorkerScheduler.php | 5 ++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/components/workers/ResqueWorker.php b/components/workers/ResqueWorker.php index e5fa6d0..57cc65a 100644 --- a/components/workers/ResqueWorker.php +++ b/components/workers/ResqueWorker.php @@ -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; } /** @@ -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; diff --git a/components/workers/base/ResqueWorkerBase.php b/components/workers/base/ResqueWorkerBase.php index bc5ba4b..57066f6 100644 --- a/components/workers/base/ResqueWorkerBase.php +++ b/components/workers/base/ResqueWorkerBase.php @@ -120,6 +120,7 @@ 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) { @@ -127,6 +128,7 @@ public function restore($workerInstance) if (!is_array($queues)) { $queues = explode(',', $queues); } + $this->queues = $queues; $this->pid = $pid; $this->id = $workerInstance; //regenerate worker @@ -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; } /** diff --git a/plugins/schedule/workers/ResqueWorkerScheduler.php b/plugins/schedule/workers/ResqueWorkerScheduler.php index c6ac6a7..7901a20 100644 --- a/plugins/schedule/workers/ResqueWorkerScheduler.php +++ b/plugins/schedule/workers/ResqueWorkerScheduler.php @@ -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;