From 90588406a00383b44dd34084c832d4842084213a Mon Sep 17 00:00:00 2001 From: Holger Reinhardt Date: Sun, 31 Jul 2016 22:58:04 +0200 Subject: [PATCH] Fix comparing jobs --- src/Job.php | 12 +++++++++++- src/Resque.php | 14 +------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Job.php b/src/Job.php index 1216ee7..6a63bbc 100644 --- a/src/Job.php +++ b/src/Job.php @@ -36,7 +36,7 @@ abstract class Job */ public function arguments() { - return $this->args; + return $this->args ?: []; } /** @@ -58,5 +58,15 @@ abstract class Job return $this; } + /** + * @param Job $job + * + * @return bool + */ + public function equals(Job $job) + { + return $this->name() === $job->name() && $this->arguments() === $job->arguments(); + } + abstract public function perform(); } diff --git a/src/Resque.php b/src/Resque.php index 1fe3715..2dd5b26 100644 --- a/src/Resque.php +++ b/src/Resque.php @@ -59,7 +59,7 @@ class Resque $queue = new Queue($job->queue()); foreach ($queue->jobs() as $queuedJob) { - if (true === $this->isSameJob($job, $queuedJob)) { + if (true === $job->equals($queuedJob)) { return ($trackStatus) ? new \Resque_Job_Status($queuedJob->job->payload['id']) : null; } } @@ -84,16 +84,4 @@ class Resque { return \Resque::fork(); } - - /** - * @param Job $job - * @param Job $queuedJob - * - * @return bool - */ - protected function isSameJob(Job $job, Job $queuedJob) - { - return $job->name() === $queuedJob->name() - && count(array_intersect($job->arguments(), $queuedJob->arguments())) === count($job->arguments()); - } }