From 0663765b4769a3360ca1f791d0e8043bcfa23139 Mon Sep 17 00:00:00 2001 From: Holger Reinhardt Date: Fri, 29 Jul 2016 15:02:27 +0200 Subject: [PATCH] fix detect duplicate job --- config/resque.php | 3 +-- src/Console/WorkCommand.php | 5 ++++- src/ResqueManager.php | 22 ++++++++-------------- src/ResqueServiceProvider.php | 2 +- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/config/resque.php b/config/resque.php index 342269d..a1cfa11 100644 --- a/config/resque.php +++ b/config/resque.php @@ -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), ], diff --git a/src/Console/WorkCommand.php b/src/Console/WorkCommand.php index 464d221..e7769bc 100644 --- a/src/Console/WorkCommand.php +++ b/src/Console/WorkCommand.php @@ -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); } /** diff --git a/src/ResqueManager.php b/src/ResqueManager.php index fc5f20b..3d9fe03 100644 --- a/src/ResqueManager.php +++ b/src/ResqueManager.php @@ -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()); } } diff --git a/src/ResqueServiceProvider.php b/src/ResqueServiceProvider.php index 9d7a81f..ec68fc3 100644 --- a/src/ResqueServiceProvider.php +++ b/src/ResqueServiceProvider.php @@ -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']); });