mirror of
https://github.com/idanoo/laravel-resque.git
synced 2024-11-21 16:11:59 +00:00
Check jobs currently worked on for duplicates
This commit is contained in:
parent
fe1cb573bf
commit
591012d123
@ -31,23 +31,6 @@ class Resque
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param bool $trackStatus
|
||||
*
|
||||
* @return null|\Resque_Job_Status
|
||||
*/
|
||||
public function enqueue(Job $job, $trackStatus = false)
|
||||
{
|
||||
$id = \Resque::enqueue($job->queue(), $job->name(), $job->arguments(), $trackStatus);
|
||||
|
||||
if (true === $trackStatus) {
|
||||
return new \Resque_Job_Status($id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param bool $trackStatus
|
||||
@ -64,9 +47,50 @@ class Resque
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->working() as $workingJob) {
|
||||
if (true === $job->equals($workingJob)) {
|
||||
return ($trackStatus) ? new \Resque_Job_Status($workingJob->job->payload['id']) : null;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->enqueue($job, $trackStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Job[]
|
||||
*/
|
||||
private function working()
|
||||
{
|
||||
$jobs = [];
|
||||
foreach (\Resque::redis()->smembers('workers') as $worker) {
|
||||
$job = \Resque::redis()->get('worker:' . $worker);
|
||||
$job = \json_decode($job, true);
|
||||
if (!\json_last_error()) {
|
||||
$jobs[] = (new \Resque_Job($job['queue'], $job['payload']))
|
||||
->getInstance();
|
||||
}
|
||||
}
|
||||
|
||||
return $jobs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Job $job
|
||||
* @param bool $trackStatus
|
||||
*
|
||||
* @return null|\Resque_Job_Status
|
||||
*/
|
||||
public function enqueue(Job $job, $trackStatus = false)
|
||||
{
|
||||
$id = \Resque::enqueue($job->queue(), $job->name(), $job->arguments(), $trackStatus);
|
||||
|
||||
if (true === $trackStatus) {
|
||||
return new \Resque_Job_Status($id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Resque_Redis
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user