Skip to content

Commit

Permalink
Merge pull request #5 from pascaldevink/symfony_3_support
Browse files Browse the repository at this point in the history
Symfony 3 compatibility
  • Loading branch information
mpclarkson authored Jul 21, 2016
2 parents c1056f3 + 846ab0e commit dd0e295
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 29 deletions.
6 changes: 5 additions & 1 deletion Command/StartScheduledWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$env = array(
'APP_INCLUDE' => $this->getContainer()->getParameter('kernel.root_dir').'/../var/bootstrap.php.cache',
'APP_INCLUDE' => $this->getContainer()->getParameter('resque.app_include'),
'VVERBOSE' => 1,
'RESQUE_PHP' => $this->getContainer()->getParameter('resque.vendor_dir').'/chrisboulton/php-resque/lib/Resque.php',
'INTERVAL' => $input->getOption('interval'),
);

if (false !== getenv('APP_INCLUDE')) {
$env['APP_INCLUDE'] = getenv('APP_INCLUDE');
}

$prefix = $this->getContainer()->getParameter('resque.prefix');
if (!empty($prefix)) {
$env['PREFIX'] = $this->getContainer()->getParameter('resque.prefix');
Expand Down
6 changes: 5 additions & 1 deletion Command/StartWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
);
}

$env['APP_INCLUDE'] = $this->getContainer()->getParameter('kernel.root_dir').'/../var/bootstrap.php.cache';
$env['APP_INCLUDE'] = $this->getContainer()->getParameter('resque.app_include');
$env['COUNT'] = $input->getOption('count');
$env['INTERVAL'] = $input->getOption('interval');
$env['QUEUE'] = $input->getArgument('queues');
$env['VERBOSE'] = 1;

if (false !== getenv('APP_INCLUDE')) {
$env['APP_INCLUDE'] = getenv('APP_INCLUDE');
}

$prefix = $this->getContainer()->getParameter('resque.prefix');
if (!empty($prefix)) {
$env['PREFIX'] = $this->getContainer()->getParameter('resque.prefix');
Expand Down
15 changes: 9 additions & 6 deletions Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Mpclarkson\ResqueBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
Expand All @@ -18,9 +19,9 @@ public function indexAction()
);
}

public function showQueueAction($queue)
public function showQueueAction($queue, Request $request)
{
list($start, $count, $showingAll) = $this->getShowParameters();
list($start, $count, $showingAll) = $this->getShowParameters($request);

$queue = $this->getResque()->getQueue($queue);
$jobs = $queue->getJobs($start, $count);
Expand All @@ -39,9 +40,9 @@ public function showQueueAction($queue)
);
}

public function listFailedAction()
public function listFailedAction(Request $request)
{
list($start, $count, $showingAll) = $this->getShowParameters();
list($start, $count, $showingAll) = $this->getShowParameters($request);

$jobs = $this->getResque()->getFailedJobs($start, $count);

Expand Down Expand Up @@ -97,15 +98,17 @@ protected function getResque()
/**
* decide which parts of a job queue to show
*
* @param Request $request
*
* @return array
*/
private function getShowParameters()
private function getShowParameters(Request $request)
{
$showingAll = false;
$start = -100;
$count = -1;

if ($this->getRequest()->query->has('all')) {
if ($request->query->has('all')) {
$start = 0;
$count = -1;
$showingAll = true;
Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function getConfigTreeBuilder()
->cannotBeEmpty()
->info('Set the vendor dir')
->end()
->scalarNode('app_include')
->defaultValue('%kernel.root_dir%/bootstrap.php.cache')
->cannotBeEmpty()
->info('Set the APP_INCLUDE for php-resque')
->end()
->scalarNode('prefix')
->defaultNull()
->end()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/ResqueExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

$container->setParameter('resque.vendor_dir', $config['vendor_dir']);
$container->setParameter('resque.app_include', $config['app_include']);
$container->setParameter('resque.class', $config['class']);
$container->setParameter('resque.redis.host', $config['redis']['host']);
$container->setParameter('resque.redis.port', $config['redis']['port']);
Expand Down
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ You may want to add some configuration to your `config.yml`
resque:
class: Mpclarkson\ResqueBundle\Resque # the resque class if different from default
vendor_dir: %kernel.root_dir%/../vendor # the vendor dir if different from default
app_include: /pathto/bootstrap.php.cache # app include file if different from default
prefix: my-resque-prefix # optional prefix to separate Resque data per site/app
redis:
host: localhost # the redis host
Expand Down
19 changes: 9 additions & 10 deletions bin/resque
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ if (empty($QUEUE)) {
}

require __DIR__ . '/../../../../app/autoload.php';
require __DIR__ . '/../../../../var/bootstrap.php.cache';

$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}

require_once $APP_INCLUDE;
}

$REDIS_BACKEND = getenv('REDIS_BACKEND');
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
Expand All @@ -29,15 +37,6 @@ if (!empty($LOGGING) || !empty($VERBOSE)) {
$logLevel = true;
}

$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}

require_once $APP_INCLUDE;
}

// See if the APP_INCLUDE containes a logger object,
// If none exists, fallback to internal logger
if (!isset($logger) || !is_object($logger)) {
Expand Down
21 changes: 10 additions & 11 deletions bin/resque-scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
<?php

require __DIR__ . '/../../../../app/autoload.php';
require __DIR__ . '/../../../../var/bootstrap.php.cache';

// Load the user's application if one exists
$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}

require_once $APP_INCLUDE;
}

// Look for an environment variable with
$RESQUE_PHP = getenv('RESQUE_PHP');
Expand Down Expand Up @@ -38,16 +47,6 @@ if (!empty($INTERVAL)) {
$interval = $INTERVAL;
}

// Load the user's application if one exists
$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
die('APP_INCLUDE ('.$APP_INCLUDE.") does not exist.\n");
}

require_once $APP_INCLUDE;
}

$PREFIX = getenv('PREFIX');
if(!empty($PREFIX)) {
fwrite(STDOUT, '*** Prefix set to '.$PREFIX."\n");
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
],
"require": {
"symfony/framework-bundle": ">=2.8,<4.0",
"symfony/console": ">=2.8,<4.0",
"symfony/process": ">=2.8,<4.0",
"chrisboulton/php-resque": "dev-master#df69e8980cc21652f10cd775cb6a0e8c572ffd2d",
"chrisboulton/php-resque-scheduler": "dev-master#ab8bd52949cac1f815bbb97aa39f51c7b5766a86"
},
Expand Down

0 comments on commit dd0e295

Please sign in to comment.