Fix comparing jobs

This commit is contained in:
Holger Reinhardt 2016-07-31 22:58:04 +02:00
parent cff14e320f
commit 90588406a0
2 changed files with 12 additions and 14 deletions

View File

@ -36,7 +36,7 @@ abstract class Job
*/ */
public function arguments() public function arguments()
{ {
return $this->args; return $this->args ?: [];
} }
/** /**
@ -58,5 +58,15 @@ abstract class Job
return $this; 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(); abstract public function perform();
} }

View File

@ -59,7 +59,7 @@ class Resque
$queue = new Queue($job->queue()); $queue = new Queue($job->queue());
foreach ($queue->jobs() as $queuedJob) { 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; return ($trackStatus) ? new \Resque_Job_Status($queuedJob->job->payload['id']) : null;
} }
} }
@ -84,16 +84,4 @@ class Resque
{ {
return \Resque::fork(); 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());
}
} }