mirror of
https://github.com/idanoo/laravel-resque.git
synced 2024-11-21 16:11:59 +00:00
refactor config
This commit is contained in:
parent
0519a18b38
commit
a0868851ea
@ -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),
|
||||
|
||||
];
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user