mirror of
https://github.com/idanoo/laravel-resque.git
synced 2024-11-21 16:11:59 +00:00
Fix comparing jobs
This commit is contained in:
parent
cff14e320f
commit
90588406a0
12
src/Job.php
12
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();
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user