diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..072705c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +vendor/ +composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bd9b2ce --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "hlgrrnhrdt/laravel-resque", + "authors": [ + { + "name": "Holger Reinhardt", + "email": "hlgrrnhrdt@gmail.com" + } + ], + "require": { + "illuminate/console": "^5.2", + "chrisboulton/php-resque": "^1.2", + "illuminate/config": "^5.2" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "autoload": { + "psr-4": { + "Hlgrrnhrdt\\Resque\\": "src/" + } + } +} diff --git a/src/Console/WorkCommand.php b/src/Console/WorkCommand.php new file mode 100644 index 0000000..e6b8354 --- /dev/null +++ b/src/Console/WorkCommand.php @@ -0,0 +1,19 @@ + + */ +class WorkCommand extends Command +{ + protected $name = 'resque:work'; + + public function fire() + { + // + } +} diff --git a/src/Job.php b/src/Job.php new file mode 100644 index 0000000..4d03fac --- /dev/null +++ b/src/Job.php @@ -0,0 +1,47 @@ + + */ +abstract class Job +{ + /** + * @var string + */ + protected $queue = 'default'; + + /** + * @var array + */ + protected $arguments = []; + + /** + * @return mixed + */ + public function queue() + { + return $this->queue; + } + + /** + * @return array + */ + public function arguments() + { + return $this->arguments; + } + + /** + * @param string $queue + * + * @return Job + */ + public function onQueue($queue) + { + $this->queue = $queue; + return $this; + } +} diff --git a/src/Queue.php b/src/Queue.php new file mode 100644 index 0000000..d8ddc5c --- /dev/null +++ b/src/Queue.php @@ -0,0 +1,22 @@ + + */ +class Queue +{ + protected $name; + + public function __construct($name) + { + $this->name = $name; + } + + public function jobs() + { + \Resque::redis()->lrange('queue:' . $this->name, 0, -1); + } +} diff --git a/src/ResqueManager.php b/src/ResqueManager.php new file mode 100644 index 0000000..c01b0fb --- /dev/null +++ b/src/ResqueManager.php @@ -0,0 +1,33 @@ + + */ +class ResqueManager +{ + /** + * @var PhpResque + */ + private $resque; + + public function __construct(PhpResque $resque) + { + $this->resque = $resque; + } + + public function enqueue(Job $job) + { + $this->resque->enqueue($job->queue(), get_class($job), $job->arguments()); + } + + public function enqueueOnce(Job $job) + { + $queue = new Queue($job->queue()); + + } +} diff --git a/src/ResqueServiceProvider.php b/src/ResqueServiceProvider.php new file mode 100644 index 0000000..c7c5774 --- /dev/null +++ b/src/ResqueServiceProvider.php @@ -0,0 +1,43 @@ + + */ +class ResqueServiceProvider extends ServiceProvider +{ + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerManager(); + $this->registerWorkCommand(); + } + + protected function registerManager() + { + $this->app->singleton(ResqueManager::class, function ($app) { + $config = $app['config']['resque.connection']; + $resque = new Resque(); + $resque->setBackend(implode(':', [$config['host'], $config['port']]), $config['db']); + return new ResqueManager($resque); + }); + } + + protected function registerWorkCommand() + { + $this->app->singleton('command.resque.work', function () { + return new WorkCommand(); + }); + } +}