diff --git a/config/resque.php b/config/resque.php index 61cf6f3..926755d 100644 --- a/config/resque.php +++ b/config/resque.php @@ -10,8 +10,9 @@ return [ */ 'connection' => [ - 'server' => env('RESQUE_REDIS_SERVER', 'localhost:6379'), - 'db' => env('RESQUE_REDIS_DB', 0), + 'host' => env('RESQUE_REDIS_HOST', 'localhost'), + 'port' => env('RESQUE_REDIS_PORT', 6379), + 'database' => env('RESQUE_REDIS_DATABASE', 0), ], /* @@ -22,6 +23,5 @@ return [ */ 'prefix' => env('RESQUE_PREFIX', null), - 'trackStatus' => env('RESQUE_TRACK_STATUS', false), ]; diff --git a/src/Resque.php b/src/Resque.php index 6965d5e..4d7f596 100644 --- a/src/Resque.php +++ b/src/Resque.php @@ -20,14 +20,6 @@ class Resque */ protected $trackStatus = false; - /** - * - */ - public function __construct($connection = null) - { - - } - /** * @param string $prefix */ @@ -64,7 +56,7 @@ class Resque $queue = new Queue($job->queue()); foreach ($queue->jobs() as $queuedJob) { - if (true === $this->isDuplicateJob($job, $queuedJob)) { + if (true === $this->isSameJob($job, $queuedJob)) { return ($trackStatus) ? new \Resque_Job_Status($queuedJob->job->payload['id']) : null; } } @@ -96,7 +88,7 @@ class Resque * * @return bool */ - private function isDuplicateJob(Job $job, Job $queuedJob) + protected function isSameJob(Job $job, Job $queuedJob) { return $job->name() === $queuedJob->name() && count(array_intersect($job->arguments(), $queuedJob->arguments())) === count($job->arguments()); diff --git a/src/ResqueServiceProvider.php b/src/ResqueServiceProvider.php index 50db87c..72c97f1 100644 --- a/src/ResqueServiceProvider.php +++ b/src/ResqueServiceProvider.php @@ -16,8 +16,7 @@ class ResqueServiceProvider extends ServiceProvider */ public function boot() { - $connection = $this->app['config']['resque.connection']; - \Resque::setBackend($connection['server'], $connection['db']); + $this->setRedisConfig(); } /** @@ -33,8 +32,8 @@ class ResqueServiceProvider extends ServiceProvider protected function registerResque() { - $this->app->singleton('resque', function () { - $prefix = $connection = $this->app['config']['resque.prefix']; + $this->app->singleton(Resque::class, function () { + $prefix = $this->app['config']['resque.prefix']; return (new Resque())->setPrefix($prefix); }); } @@ -42,8 +41,21 @@ class ResqueServiceProvider extends ServiceProvider protected function registerWorkCommand() { $this->app->singleton('command.resque.work', function () { - return new WorkCommand($this->app->make('resque.manager')); + return new WorkCommand($this->app->make(Resque::class)); }); $this->commands('command.resque.work'); } + + protected function setRedisConfig() + { + $config = $this->app['config']['resque.connection']; + + $host = isset($config['host']) ? $config['host'] : 'localhost'; + $port = isset($config['port']) ? $config['port'] : 6379; + $database = isset($config['database']) ? $config['database'] : 0; + + $server = implode(':', [$host, $port]); + + \Resque::setBackend($server, $database); + } }