initial commit

This commit is contained in:
Holger Reinhardt 2016-07-28 23:52:05 +02:00
parent 81d0771154
commit c563d0e4ae
7 changed files with 189 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea/
vendor/
composer.lock

22
composer.json Normal file
View File

@ -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/"
}
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Hlgrrnhrdt\Resque\Console;
use Illuminate\Console\Command;
/**
* WorkCommand
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
class WorkCommand extends Command
{
protected $name = 'resque:work';
public function fire()
{
//
}
}

47
src/Job.php Normal file
View File

@ -0,0 +1,47 @@
<?php
namespace Hlgrrnhrdt\Resque;
/**
* Job
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
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;
}
}

22
src/Queue.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace Hlgrrnhrdt\Resque;
/**
* Queue
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
class Queue
{
protected $name;
public function __construct($name)
{
$this->name = $name;
}
public function jobs()
{
\Resque::redis()->lrange('queue:' . $this->name, 0, -1);
}
}

33
src/ResqueManager.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace Hlgrrnhrdt\Resque;
use Resque as PhpResque;
/**
* Resque
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
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());
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace Hlgrrnhrdt\Resque;
use Config;
use Hlgrrnhrdt\Resque\Console\WorkCommand;
use Illuminate\Support\ServiceProvider;
use Resque;
/**
* ResqueServiceProvider
*
* @author Holger Reinhardt <hlgrrnhrdt@gmail.com>
*/
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();
});
}
}