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' => [
|
'connection' => [
|
||||||
'server' => env('RESQUE_REDIS_SERVER', 'localhost:6379'),
|
'host' => env('RESQUE_REDIS_HOST', 'localhost'),
|
||||||
'db' => env('RESQUE_REDIS_DB', 0),
|
'port' => env('RESQUE_REDIS_PORT', 6379),
|
||||||
|
'database' => env('RESQUE_REDIS_DATABASE', 0),
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -22,6 +23,5 @@ return [
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
'prefix' => env('RESQUE_PREFIX', null),
|
'prefix' => env('RESQUE_PREFIX', null),
|
||||||
'trackStatus' => env('RESQUE_TRACK_STATUS', false),
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -20,14 +20,6 @@ class Resque
|
|||||||
*/
|
*/
|
||||||
protected $trackStatus = false;
|
protected $trackStatus = false;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function __construct($connection = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $prefix
|
* @param string $prefix
|
||||||
*/
|
*/
|
||||||
@ -64,7 +56,7 @@ class Resque
|
|||||||
$queue = new Queue($job->queue());
|
$queue = new Queue($job->queue());
|
||||||
|
|
||||||
foreach ($queue->jobs() as $queuedJob) {
|
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;
|
return ($trackStatus) ? new \Resque_Job_Status($queuedJob->job->payload['id']) : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +88,7 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isDuplicateJob(Job $job, Job $queuedJob)
|
protected function isSameJob(Job $job, Job $queuedJob)
|
||||||
{
|
{
|
||||||
return $job->name() === $queuedJob->name()
|
return $job->name() === $queuedJob->name()
|
||||||
&& count(array_intersect($job->arguments(), $queuedJob->arguments())) === count($job->arguments());
|
&& count(array_intersect($job->arguments(), $queuedJob->arguments())) === count($job->arguments());
|
||||||
|
@ -16,8 +16,7 @@ class ResqueServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$connection = $this->app['config']['resque.connection'];
|
$this->setRedisConfig();
|
||||||
\Resque::setBackend($connection['server'], $connection['db']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,8 +32,8 @@ class ResqueServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
protected function registerResque()
|
protected function registerResque()
|
||||||
{
|
{
|
||||||
$this->app->singleton('resque', function () {
|
$this->app->singleton(Resque::class, function () {
|
||||||
$prefix = $connection = $this->app['config']['resque.prefix'];
|
$prefix = $this->app['config']['resque.prefix'];
|
||||||
return (new Resque())->setPrefix($prefix);
|
return (new Resque())->setPrefix($prefix);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -42,8 +41,21 @@ class ResqueServiceProvider extends ServiceProvider
|
|||||||
protected function registerWorkCommand()
|
protected function registerWorkCommand()
|
||||||
{
|
{
|
||||||
$this->app->singleton('command.resque.work', function () {
|
$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');
|
$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