mirror of
https://github.com/idanoo/laravel-resque.git
synced 2024-11-21 16:11:59 +00:00
initial commit
This commit is contained in:
parent
81d0771154
commit
c563d0e4ae
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
vendor/
|
||||
composer.lock
|
22
composer.json
Normal file
22
composer.json
Normal 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/"
|
||||
}
|
||||
}
|
||||
}
|
19
src/Console/WorkCommand.php
Normal file
19
src/Console/WorkCommand.php
Normal 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
47
src/Job.php
Normal 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
22
src/Queue.php
Normal 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
33
src/ResqueManager.php
Normal 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());
|
||||
|
||||
}
|
||||
}
|
43
src/ResqueServiceProvider.php
Normal file
43
src/ResqueServiceProvider.php
Normal 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();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user