mirror of
https://github.com/idanoo/laravel-resque.git
synced 2024-11-24 01:15:19 +00:00
fix detect duplicate job
This commit is contained in:
parent
e230e66b48
commit
0663765b47
@ -10,8 +10,7 @@ return [
|
||||
*/
|
||||
|
||||
'connection' => [
|
||||
'host' => env('RESQUE_REDIS_HOST', 'localhost'),
|
||||
'port' => env('RESQUE_REDIS_PORT', 6379),
|
||||
'server' => env('RESQUE_REDIS_SERVER', 'localhost:6379'),
|
||||
'db' => env('RESQUE_REDIS_DB', 0),
|
||||
],
|
||||
|
||||
|
@ -76,8 +76,11 @@ class WorkCommand extends IlluminateCommand
|
||||
*/
|
||||
private function startWorker(array $queues, $interval = 5, $logLevel = Resque_Worker::LOG_NONE)
|
||||
{
|
||||
$worker = $this->manager->startWorker($queues, $interval, $logLevel);
|
||||
$worker = new Resque_Worker($queues);
|
||||
$worker->logLevel = $logLevel;
|
||||
|
||||
$this->info(sprintf('Starting worker %s', $worker));
|
||||
$worker->work($interval);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,10 +62,8 @@ class ResqueManager
|
||||
$queue = new Queue($job->queue());
|
||||
|
||||
foreach ($queue->jobs() as $queuedJob) {
|
||||
if ($job->payload['class'] === get_class($queuedJob) && count(array_intersect($queuedJob->getArguments(),
|
||||
$job->arguments())) === $job->arguments()
|
||||
) {
|
||||
return ($trackStatus) ? new \Resque_Job_Status($job->payload['id']) : null;
|
||||
if (true === $this->isDuplicateJob($job, $queuedJob)) {
|
||||
return ($trackStatus) ? new \Resque_Job_Status($queuedJob->payload['id']) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,18 +98,14 @@ class ResqueManager
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $queues
|
||||
* @param int $interval
|
||||
* @param int $logLevel
|
||||
* @param \Hlgrrnhrdt\Resque\Job $job
|
||||
* @param $queuedJob
|
||||
*
|
||||
* @return \Resque_Worker
|
||||
* @return bool
|
||||
*/
|
||||
public function startWorker(array $queues, $interval = 5, $logLevel = Resque_Worker::LOG_NONE)
|
||||
private function isDuplicateJob(Job $job, \Resque_Job $queuedJob)
|
||||
{
|
||||
$worker = new Resque_Worker($queues);
|
||||
$worker->logLevel = $logLevel;
|
||||
$worker->work($interval);
|
||||
|
||||
return $worker;
|
||||
return $queuedJob->payload['class'] === get_class($queuedJob)
|
||||
&& count(array_intersect($queuedJob->getArguments(), $job->arguments())) === count($job->arguments());
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class ResqueServiceProvider extends ServiceProvider
|
||||
$config = $this->app['config']['resque.connection'];
|
||||
|
||||
$resque = new Resque();
|
||||
$resque->setBackend(implode(':', [$config['host'], $config['port']]), $config['db']);
|
||||
$resque->setBackend($config['server'], $config['db']);
|
||||
|
||||
return new ResqueManager($resque, $this->app['config']['resque.trackStatus']);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user