From c62ff28146c2515b1e27255feed0647ce9464fda Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Sun, 6 Jun 2021 20:13:49 +0100 Subject: [PATCH 01/10] Catch Error as well as Exception --- bin/resque | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/resque b/bin/resque index 15b3fd6..d296228 100755 --- a/bin/resque +++ b/bin/resque @@ -106,7 +106,7 @@ if (!empty($PREFIX)) { } // If set, re-attach failed jobs based on retry_strategy -Resque_Event::listen('onFailure', function (Exception $exception, Resque_Job $job) use ($logger, $sentryClient) { +Resque_Event::listen('onFailure', function (Error | Exception $exception, Resque_Job $job) use ($logger, $sentryClient) { // Allow integration with Sentry.io if (null !== $sentryClient){ From c5b8d08bcb7aaf41a40d75e7d21d2032dd227b07 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Tue, 22 Jun 2021 09:34:44 +0100 Subject: [PATCH 02/10] Correctly return exit codes from commands --- Command/CleanUpWorkersCommand.php | 2 ++ Command/ClearQueueCommand.php | 2 +- Command/PingTestCommand.php | 2 +- Command/StartScheduledWorkerCommand.php | 2 ++ Command/StartWorkerCommand.php | 2 ++ Command/StopScheduledWorkerCommand.php | 4 ++-- Command/StopWorkerCommand.php | 6 +++--- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Command/CleanUpWorkersCommand.php b/Command/CleanUpWorkersCommand.php index f5d3e5b..22c1093 100644 --- a/Command/CleanUpWorkersCommand.php +++ b/Command/CleanUpWorkersCommand.php @@ -49,5 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $worker->getWorker()->unregisterWorker(); } } + + return Command::SUCCESS; } } diff --git a/Command/ClearQueueCommand.php b/Command/ClearQueueCommand.php index c495ee2..31ca1d4 100644 --- a/Command/ClearQueueCommand.php +++ b/Command/ClearQueueCommand.php @@ -48,6 +48,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Cleared queue '.$queue.' - removed '.$count.' entries'); - return 0; + return Command::SUCCESS; } } diff --git a/Command/PingTestCommand.php b/Command/PingTestCommand.php index eac111f..c4e96c6 100644 --- a/Command/PingTestCommand.php +++ b/Command/PingTestCommand.php @@ -45,6 +45,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $job = new PingJob(); $output->writeln($this->resque->enqueue($job, true)); - return 0; + return Command::SUCCESS; } } diff --git a/Command/StartScheduledWorkerCommand.php b/Command/StartScheduledWorkerCommand.php index 6e3ec2e..da53403 100644 --- a/Command/StartScheduledWorkerCommand.php +++ b/Command/StartScheduledWorkerCommand.php @@ -144,5 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf('Worker started %s:%s', $hostname, $pid)); file_put_contents($pidFile, $pid); } + + return Command::SUCCESS; } } diff --git a/Command/StartWorkerCommand.php b/Command/StartWorkerCommand.php index 63fc1e2..cc75907 100644 --- a/Command/StartWorkerCommand.php +++ b/Command/StartWorkerCommand.php @@ -169,5 +169,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf('Worker started %s:%s:%s', $hostname, $pid, $input->getArgument('queues'))); } } + + return Command::SUCCESS; } } diff --git a/Command/StopScheduledWorkerCommand.php b/Command/StopScheduledWorkerCommand.php index dbe0530..84b8a8b 100644 --- a/Command/StopScheduledWorkerCommand.php +++ b/Command/StopScheduledWorkerCommand.php @@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!file_exists($pidFile)) { $output->writeln('No PID file found'); - return -1; + return Command::FAILURE; } $pid = file_get_contents($pidFile); @@ -57,6 +57,6 @@ protected function execute(InputInterface $input, OutputInterface $output) unlink($pidFile); - return 0; + return Command::SUCCESS; } } diff --git a/Command/StopWorkerCommand.php b/Command/StopWorkerCommand.php index 37422e3..1a424ca 100644 --- a/Command/StopWorkerCommand.php +++ b/Command/StopWorkerCommand.php @@ -62,7 +62,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('There are no running workers.'); } - return 1; + return Command::FAILURE; } $workers = [$worker]; @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!\count($workers)) { $output->writeln('There are no running workers to stop.'); - return 0; + return Command::SUCCESS; } foreach ($workers as $worker) { @@ -84,6 +84,6 @@ protected function execute(InputInterface $input, OutputInterface $output) } } - return 0; + return Command::SUCCESS; } } From fe39e37516e67d88be7bc489d40e31bb538be1e3 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Tue, 22 Jun 2021 09:45:18 +0100 Subject: [PATCH 03/10] update requirements --- README.markdown | 10 ++++++++-- composer.json | 12 ++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.markdown b/README.markdown index 1ee8993..00e6369 100644 --- a/README.markdown +++ b/README.markdown @@ -1,18 +1,24 @@ [![Build Status](https://travis-ci.org/resquebundle/resque.svg?branch=master)](https://travis-ci.org/resquebundle/resque) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/resquebundle/resque/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/resquebundle/resque/?branch=master) -**This project IS under ACTIVE development (last major update May 2020)** +**This project IS under ACTIVE development (last major update June 2021)** # ResqueBundle ## Compatibiltiy - - For Symfony 5+ please use ResqueBundle v4.0.0+ + - For Symfony 5+ / PHP8 please use ResqueBundle v5+ - For Symfony 4+ please use major series ResqueBundle v3+ and work towards Symfony 5 migration ;-) - For Symfony 3+ please peg to exact release ResqueBundle v2.0.9+ and think about your decision to even use Symfony 3 ;-) Note that we dont offer the same b/c promise as symfony itself, but try our hardest to make major versions for major symfony versions. +## Update June 2021 + + - New series 5.x to be Symfony 5.3 and PHP 8 compatible only. + - Return correct command exit statuses + - Catch correct Exceptions and new TypeError Exception + ## Update May 2020 - Inject ParameterBagInterface instead of directly accessing container in commands and controller diff --git a/composer.json b/composer.json index 46e8f47..503f979 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,13 @@ { "name": "resquebundle/resque", "type": "symfony-bundle", - "description": "A Symfony 4 bundle to manage Resque job queues", + "description": "A Symfony 5 bundle to manage Resque job queues", "keywords": [ "resque", "job queue", "queue", "symfony", - "symfony4", + "symfony5", "redis" ], "homepage": "https://github.com/resquebundle/resque/", @@ -30,10 +30,10 @@ } ], "require": { - "php": ">=7.1", - "symfony/framework-bundle": "^4.1.2 || ^5.0", - "symfony/console": "^4.1.2 || ^5.0", - "symfony/process": "^4.1.2 || ^5.0", + "php": ">=8", + "symfony/framework-bundle": "^5.3", + "symfony/console": "^5.3", + "symfony/process": "^5.3", "resque/php-resque": "^1.3" }, "require-dev": { From 6cfcc4fca1957512f1e7b5f402b4c81cd6a28eef Mon Sep 17 00:00:00 2001 From: Matthew Rardon Date: Tue, 3 Aug 2021 15:21:35 -0400 Subject: [PATCH 04/10] Add auth to StartWorkerCommand --- Command/StartWorkerCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Command/StartWorkerCommand.php b/Command/StartWorkerCommand.php index cc75907..69c4fcb 100644 --- a/Command/StartWorkerCommand.php +++ b/Command/StartWorkerCommand.php @@ -97,6 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $redisHost = $this->params->get('resque.redis.host'); $redisPort = $this->params->get('resque.redis.port'); $redisDatabase = $this->params->get('resque.redis.database'); + $redisPassword = $this->params->get('resque.redis.password'); if (null != $redisHost && null != $redisPort) { $env['REDIS_BACKEND'] = $redisHost.':'.$redisPort; @@ -106,6 +107,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $env['REDIS_BACKEND_DB'] = $redisDatabase; } + if (isset($redisPassword)) { + $env['REDIS_BACKEND_PASSWORD'] = $redisPassword; + } + $opt = ''; if (0 !== $m = (int) $input->getOption('memory-limit')) { $opt = sprintf('-d memory_limit=%dM', $m); From 8777fa9cb9cbb65b36bcebb0a086ee133d280cc7 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Mon, 6 Sep 2021 10:28:13 +0100 Subject: [PATCH 05/10] Clean up commands and move to attributes --- Command/CleanUpWorkersCommand.php | 24 +++++++++--------------- Command/ClearQueueCommand.php | 21 +++++++++------------ Command/PingTestCommand.php | 24 +++++++++--------------- Command/StartScheduledWorkerCommand.php | 18 ++++++++---------- Command/StartWorkerCommand.php | 18 ++++++++---------- Command/StopScheduledWorkerCommand.php | 23 ++++++++--------------- Command/StopWorkerCommand.php | 18 ++++++++---------- 7 files changed, 59 insertions(+), 87 deletions(-) diff --git a/Command/CleanUpWorkersCommand.php b/Command/CleanUpWorkersCommand.php index 22c1093..a118e26 100644 --- a/Command/CleanUpWorkersCommand.php +++ b/Command/CleanUpWorkersCommand.php @@ -8,29 +8,23 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use ResqueBundle\Resque\Resque; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -/** - * Class CleanUpWorkersCommand. - */ +#[AsCommand( + name: 'resque:cleanup:workers', + description: 'Unregisters all workers in Redis. Workers may need to be restarted.', +)] class CleanUpWorkersCommand extends Command { - private $resque; - - public function __construct(string $name = null, Resque $resque) - { - $this->resque = $resque; - parent::__construct($name); - } - - protected function configure() + public function __construct( + private Resque $resque + ) { - $this - ->setName('resque:cleanup:workers') - ->setDescription('Unregisters all workers in Redis. Workers may need to be restarted.'); + parent::__construct(); } /** diff --git a/Command/ClearQueueCommand.php b/Command/ClearQueueCommand.php index 31ca1d4..093e9e2 100644 --- a/Command/ClearQueueCommand.php +++ b/Command/ClearQueueCommand.php @@ -8,31 +8,28 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use ResqueBundle\Resque\Resque; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -/** - * Class ClearQueueCommand. - */ +#[AsCommand( + name: 'resque:clear-queue', + description: 'Clear a resque queue', +)] class ClearQueueCommand extends Command { - private $resque; - - public function __construct(string $name = null, Resque $resque) + public function __construct( + private Resque $resque) { - $this->resque = $resque; - parent::__construct($name); + parent::__construct(); } protected function configure() { - $this - ->setName('resque:clear-queue') - ->setDescription('Clear a resque queue') - ->addArgument('queue', InputArgument::REQUIRED, 'Queue name'); + $this->addArgument('queue', InputArgument::REQUIRED, 'Queue name'); } /** diff --git a/Command/PingTestCommand.php b/Command/PingTestCommand.php index c4e96c6..09181a0 100644 --- a/Command/PingTestCommand.php +++ b/Command/PingTestCommand.php @@ -8,30 +8,24 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use ResqueBundle\Resque\ExampleJobs\PingJob; use ResqueBundle\Resque\Resque; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -/** - * Class PingTestCommand. - */ +#[AsCommand( + name: 'resque:pingtest', + description: 'Send a Ping as a test, and let a job reply with pong', +)] class PingTestCommand extends Command { - private $resque; - - public function __construct(string $name = null, Resque $resque) - { - $this->resque = $resque; - parent::__construct($name); - } - - protected function configure() + public function __construct( + private Resque $resque + ) { - $this - ->setName('resque:pingtest') - ->setDescription('Send a Ping as a test, and let a job reply with pong'); + parent::__construct(); } /** diff --git a/Command/StartScheduledWorkerCommand.php b/Command/StartScheduledWorkerCommand.php index da53403..7cb0aa4 100644 --- a/Command/StartScheduledWorkerCommand.php +++ b/Command/StartScheduledWorkerCommand.php @@ -8,6 +8,7 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -15,24 +16,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Process\Process; -/** - * Class StartScheduledWorkerCommand. - */ +#[AsCommand( + name: 'resque:scheduledworker-start', + description: 'Start a scheduled resque worker', +)] class StartScheduledWorkerCommand extends Command { - private $params; - - public function __construct(string $name = null, ParameterBagInterface $params) + public function __construct( + private ParameterBagInterface $params) { - $this->params = $params; - parent::__construct($name); + parent::__construct(); } protected function configure() { $this - ->setName('resque:scheduledworker-start') - ->setDescription('Start a scheduled resque worker') ->addOption('foreground', 'f', InputOption::VALUE_NONE, 'Should the worker run in foreground') ->addOption('force', null, InputOption::VALUE_NONE, 'Force creation of a new worker if the PID file exists') ->addOption('interval', 'i', InputOption::VALUE_REQUIRED, 'How often to check for new jobs across the queues', 5); diff --git a/Command/StartWorkerCommand.php b/Command/StartWorkerCommand.php index cc75907..235bc02 100644 --- a/Command/StartWorkerCommand.php +++ b/Command/StartWorkerCommand.php @@ -8,6 +8,7 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -16,24 +17,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Process\Process; -/** - * Class StartWorkerCommand. - */ +#[AsCommand( + name: 'resque:worker-start', + description: 'Start a resque worker', +)] class StartWorkerCommand extends Command { - private $params; - - public function __construct(string $name = null, ParameterBagInterface $params) + public function __construct( + private ParameterBagInterface $params) { - $this->params = $params; - parent::__construct($name); + parent::__construct(); } protected function configure() { $this - ->setName('resque:worker-start') - ->setDescription('Start a resque worker') ->addArgument('queues', InputArgument::REQUIRED, 'Queue names (separate using comma)') ->addOption('count', 'c', InputOption::VALUE_REQUIRED, 'How many workers to fork', 1) ->addOption('interval', 'i', InputOption::VALUE_REQUIRED, 'How often to check for new jobs across the queues', 5) diff --git a/Command/StopScheduledWorkerCommand.php b/Command/StopScheduledWorkerCommand.php index 84b8a8b..bc7125f 100644 --- a/Command/StopScheduledWorkerCommand.php +++ b/Command/StopScheduledWorkerCommand.php @@ -8,29 +8,22 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; -/** - * Class StopScheduledWorkerCommand. - */ +#[AsCommand( + name: 'resque:scheduledworker-stop', + description: 'Stop a resque scheduled worker', +)] class StopScheduledWorkerCommand extends Command { - private $params; - - public function __construct(string $name = null, ParameterBagInterface $params) - { - $this->params = $params; - parent::__construct($name); - } - - protected function configure() + public function __construct( + private ParameterBagInterface $params) { - $this - ->setName('resque:scheduledworker-stop') - ->setDescription('Stop a resque scheduled worker'); + parent::__construct(); } /** diff --git a/Command/StopWorkerCommand.php b/Command/StopWorkerCommand.php index 1a424ca..c7eb2e8 100644 --- a/Command/StopWorkerCommand.php +++ b/Command/StopWorkerCommand.php @@ -8,6 +8,7 @@ namespace ResqueBundle\Resque\Command; +use Symfony\Component\Console\Attribute\AsCommand; use ResqueBundle\Resque\Resque; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -15,24 +16,21 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -/** - * Class StopWorkerCommand. - */ +#[AsCommand( + name: 'resque:worker-stop', + description: 'Stop a resque worker', +)] class StopWorkerCommand extends Command { - private $resque; - - public function __construct(string $name = null, Resque $resque) + public function __construct( + private Resque $resque) { - $this->resque = $resque; - parent::__construct($name); + parent::__construct(); } protected function configure() { $this - ->setName('resque:worker-stop') - ->setDescription('Stop a resque worker') ->addArgument('id', InputArgument::OPTIONAL, 'Worker id') ->addOption('all', 'a', InputOption::VALUE_NONE, 'Should kill all workers'); } From 6f9cb610d8250b854d6398b42880efa3d79e5f9a Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Wed, 6 Oct 2021 12:41:10 +0100 Subject: [PATCH 06/10] remove travis EOL Signed-off-by: Phil E. Taylor --- .travis.yml | 29 ----------------------------- README.markdown | 1 - 2 files changed, 30 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1344a5d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: php -php: - - 7.1 - - 7.3 - -before_script: - - composer install - -matrix: - fast_finish: true - include: - - php: 7.1 - env: SYMFONY_VERSION=4.0.* - - php: 7.3 - env: SYMFONY_VERSION=4.4.* DEPENDENCIES=beta - -sudo: false - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi; - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/framework-bundle:${SYMFONY_VERSION}" --no-update; fi; - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/console:${SYMFONY_VERSION}" --no-update; fi; - - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/process:${SYMFONY_VERSION}" --no-update; fi; - -install: composer update --prefer-dist --no-interaction $COMPOSER_FLAGS diff --git a/README.markdown b/README.markdown index 00e6369..b3b2154 100644 --- a/README.markdown +++ b/README.markdown @@ -1,4 +1,3 @@ -[![Build Status](https://travis-ci.org/resquebundle/resque.svg?branch=master)](https://travis-ci.org/resquebundle/resque) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/resquebundle/resque/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/resquebundle/resque/?branch=master) **This project IS under ACTIVE development (last major update June 2021)** From b71fc90c9a3f28a58c630363a918ff30de0c3b43 Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Wed, 6 Oct 2021 11:41:52 +0000 Subject: [PATCH 07/10] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- Command/ClearQueueCommand.php | 2 +- Command/StartScheduledWorkerCommand.php | 36 ++++++++++++------------- Command/StartWorkerCommand.php | 30 ++++++++++----------- Command/StopScheduledWorkerCommand.php | 4 +-- ContainerAwareJob.php | 6 ++--- Controller/DefaultController.php | 8 +++--- DependencyInjection/Configuration.php | 4 +-- DependencyInjection/ResqueExtension.php | 2 +- Queue.php | 6 ++--- Resque.php | 12 ++++----- Worker.php | 4 +-- 11 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Command/ClearQueueCommand.php b/Command/ClearQueueCommand.php index 093e9e2..1cacedd 100644 --- a/Command/ClearQueueCommand.php +++ b/Command/ClearQueueCommand.php @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $queue = $input->getArgument('queue'); $count = $this->resque->clearQueue($queue); - $output->writeln('Cleared queue '.$queue.' - removed '.$count.' entries'); + $output->writeln('Cleared queue ' . $queue . ' - removed ' . $count . ' entries'); return Command::SUCCESS; } diff --git a/Command/StartScheduledWorkerCommand.php b/Command/StartScheduledWorkerCommand.php index 7cb0aa4..0ded1d7 100644 --- a/Command/StartScheduledWorkerCommand.php +++ b/Command/StartScheduledWorkerCommand.php @@ -46,7 +46,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $pidFile = $this->params->get('kernel.cache_dir').'/resque_scheduledworker.pid'; + $pidFile = $this->params->get('kernel.cache_dir') . '/resque_scheduledworker.pid'; if (file_exists($pidFile) && !$input->getOption('force')) { throw new \Exception('PID file exists - use --force to override'); } @@ -58,31 +58,31 @@ protected function execute(InputInterface $input, OutputInterface $output) $env = [ 'APP_INCLUDE' => $this->params->get('resque.app_include'), 'VVERBOSE' => 1, - 'RESQUE_PHP' => $this->params->get('resque.vendor_dir').'/chrisboulton/php-resque/lib/Resque.php', + 'RESQUE_PHP' => $this->params->get('resque.vendor_dir') . '/chrisboulton/php-resque/lib/Resque.php', 'INTERVAL' => $input->getOption('interval'), ]; if (!file_exists($env['RESQUE_PHP'])) { - $env['RESQUE_PHP'] = $this->params->get('resque.vendor_dir').'/resque/php-resque/lib/Resque.php'; + $env['RESQUE_PHP'] = $this->params->get('resque.vendor_dir') . '/resque/php-resque/lib/Resque.php'; } if (false !== getenv('APP_INCLUDE')) { $env['APP_INCLUDE'] = getenv('APP_INCLUDE'); } - $prefix = $this->params->get('resque.prefix'); + $prefix = $this->params->get('resque.prefix'); if (!empty($prefix)) { - $env['PREFIX'] = $this->params->get('resque.prefix'); + $env['PREFIX'] = $this->params->get('resque.prefix'); } - $redisHost = $this->params->get('resque.redis.host'); - $redisPort = $this->params->get('resque.redis.port'); - $redisDatabase = $this->params->get('resque.redis.database'); - $redisPassword = $this->params->get('resque.redis.password'); + $redisHost = $this->params->get('resque.redis.host'); + $redisPort = $this->params->get('resque.redis.port'); + $redisDatabase = $this->params->get('resque.redis.database'); + $redisPassword = $this->params->get('resque.redis.password'); if (null != $redisHost && null != $redisPort) { - $env['REDIS_BACKEND'] = $redisHost.':'.$redisPort; + $env['REDIS_BACKEND'] = $redisHost . ':' . $redisPort; } if (isset($redisDatabase)) { @@ -96,20 +96,20 @@ protected function execute(InputInterface $input, OutputInterface $output) if (version_compare(PHP_VERSION, '5.4.0') >= 0) { $phpExecutable = PHP_BINARY; } else { - $phpExecutable = PHP_BINDIR.'/php'; + $phpExecutable = PHP_BINDIR . '/php'; if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $phpExecutable = 'php'; } } - $workdirectory = __DIR__.'/../bin/'; - $workerCommand = $phpExecutable.' '.$workdirectory.'resque-scheduler'; + $workdirectory = __DIR__ . '/../bin/'; + $workerCommand = $phpExecutable . ' ' . $workdirectory . 'resque-scheduler'; if (!$input->getOption('foreground')) { - $logFile = $this->params->get( + $logFile = $this->params->get( 'kernel.logs_dir' - ).'/resque-scheduler_'.$this->params->get('kernel.environment').'.log'; - $workerCommand = 'nohup '.$workerCommand.' > '.$logFile.' 2>&1 & echo $!'; + ) . '/resque-scheduler_' . $this->params->get('kernel.environment') . '.log'; + $workerCommand = 'nohup ' . $workerCommand . ' > ' . $logFile . ' 2>&1 & echo $!'; } // In windows: When you pass an environment to CMD it replaces the old environment @@ -117,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // this is a workaround where we add the vars to the existing environment. if (\defined('PHP_WINDOWS_VERSION_BUILD')) { foreach ($env as $key => $value) { - putenv($key.'='.$value); + putenv($key . '=' . $value); } $env = null; } @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln(sprintf('Starting worker %s', $process->getCommandLine())); if ($input->getOption('foreground')) { - $process->run(function ($type, $buffer) use ($output) { + $process->run(function($type, $buffer) use ($output) { $output->write($buffer); }); } // else we recompose and display the worker id diff --git a/Command/StartWorkerCommand.php b/Command/StartWorkerCommand.php index beb14fa..242e5d2 100644 --- a/Command/StartWorkerCommand.php +++ b/Command/StartWorkerCommand.php @@ -62,15 +62,15 @@ protected function execute(InputInterface $input, OutputInterface $output) ); } - $env['APP_INCLUDE'] = $this->params->get('resque.app_include'); + $env['APP_INCLUDE'] = $this->params->get('resque.app_include'); $env['COUNT'] = $input->getOption('count'); $env['INTERVAL'] = $input->getOption('interval'); $env['QUEUE'] = $input->getArgument('queues'); // Allow Sentry.io integration if ($this->params->has('sentry.dsn')) { - if ($sentryDSN = $this->params->get('sentry.dsn')) { - $output->writeln('Enabling Sentry Reporting to DSN '.$sentryDSN); + if ($sentryDSN = $this->params->get('sentry.dsn')) { + $output->writeln('Enabling Sentry Reporting to DSN ' . $sentryDSN); $env['SENTRY_DSN'] = $sentryDSN; } } @@ -79,9 +79,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $env['APP_INCLUDE'] = getenv('APP_INCLUDE'); } - $prefix = $this->params->get('resque.prefix'); + $prefix = $this->params->get('resque.prefix'); if (!empty($prefix)) { - $env['PREFIX'] = $this->params->get('resque.prefix'); + $env['PREFIX'] = $this->params->get('resque.prefix'); } if ($input->getOption('verbose')) { @@ -92,13 +92,13 @@ protected function execute(InputInterface $input, OutputInterface $output) unset($env['VERBOSE']); } - $redisHost = $this->params->get('resque.redis.host'); - $redisPort = $this->params->get('resque.redis.port'); - $redisDatabase = $this->params->get('resque.redis.database'); - $redisPassword = $this->params->get('resque.redis.password'); + $redisHost = $this->params->get('resque.redis.host'); + $redisPort = $this->params->get('resque.redis.port'); + $redisDatabase = $this->params->get('resque.redis.database'); + $redisPassword = $this->params->get('resque.redis.password'); if (null != $redisHost && null != $redisPort) { - $env['REDIS_BACKEND'] = $redisHost.':'.$redisPort; + $env['REDIS_BACKEND'] = $redisHost . ':' . $redisPort; } if (isset($redisDatabase)) { @@ -110,14 +110,14 @@ protected function execute(InputInterface $input, OutputInterface $output) } $opt = ''; - if (0 !== $m = (int) $input->getOption('memory-limit')) { + if (0 !== $m = (int)$input->getOption('memory-limit')) { $opt = sprintf('-d memory_limit=%dM', $m); } if (version_compare(PHP_VERSION, '5.4.0') >= 0) { $phpExecutable = PHP_BINARY; } else { - $phpExecutable = PHP_BINDIR.'/php'; + $phpExecutable = PHP_BINDIR . '/php'; if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $phpExecutable = 'php'; } @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $workerCommand = strtr('%php% %opt% %dir%/resque', [ '%php%' => $phpExecutable, '%opt%' => $opt, - '%dir%' => __DIR__.'/../bin', + '%dir%' => __DIR__ . '/../bin', ]); if (!$input->getOption('foreground')) { @@ -141,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // this is a workaround where we add the vars to the existing environment. if (\defined('PHP_WINDOWS_VERSION_BUILD')) { foreach ($env as $key => $value) { - putenv($key.'='.$value); + putenv($key . '=' . $value); } $env = null; } @@ -154,7 +154,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // if foreground, we redirect output if ($input->getOption('foreground')) { - $process->run(function ($type, $buffer) use ($output) { + $process->run(function($type, $buffer) use ($output) { $output->write($buffer); }); } // else we recompose and display the worker id diff --git a/Command/StopScheduledWorkerCommand.php b/Command/StopScheduledWorkerCommand.php index bc7125f..cf63e3d 100644 --- a/Command/StopScheduledWorkerCommand.php +++ b/Command/StopScheduledWorkerCommand.php @@ -34,7 +34,7 @@ public function __construct( */ protected function execute(InputInterface $input, OutputInterface $output) { - $pidFile = $this->params->get('kernel.cache_dir').'/resque_scheduledworker.pid'; + $pidFile = $this->params->get('kernel.cache_dir') . '/resque_scheduledworker.pid'; if (!file_exists($pidFile)) { $output->writeln('No PID file found'); @@ -44,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $pid = file_get_contents($pidFile); - $output->writeln('Killing process '.$pid); + $output->writeln('Killing process ' . $pid); posix_kill($pid, SIGKILL); diff --git a/ContainerAwareJob.php b/ContainerAwareJob.php index beda44b..8bb6075 100644 --- a/ContainerAwareJob.php +++ b/ContainerAwareJob.php @@ -56,7 +56,7 @@ protected function getContainer() protected function createKernel() { $finder = new Finder(); - $finder->name('*Kernel.php')->depth('<=1')->in($this->args['kernel.project_dir'].'/src'); + $finder->name('*Kernel.php')->depth('<=1')->in($this->args['kernel.project_dir'] . '/src'); $results = iterator_to_array($finder); $file = current($results); $class = $file->getBasename('.php'); @@ -64,8 +64,8 @@ protected function createKernel() // Take into account any namespace preg_match('/namespace\s(.*)\;/', file_get_contents($file), $matches); if (2 == \count($matches)) { - $namespace = '\\'.$matches[1].'\\'; - $class = $namespace.$class; + $namespace = '\\' . $matches[1] . '\\'; + $class = $namespace . $class; } require_once $file; diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php index 8ca2dab..d731c8b 100644 --- a/Controller/DefaultController.php +++ b/Controller/DefaultController.php @@ -76,7 +76,7 @@ public function removeQueueAction($queue, Request $request) $count = $queue->clear(); $queue->remove(); - $this->addFlash('info', 'Remove '.$queue->getName().' queue and '.$count.' jobs.'); + $this->addFlash('info', 'Remove ' . $queue->getName() . ' queue and ' . $count . ' jobs.'); return $this->redirectToRoute('ResqueBundle_homepage'); } @@ -183,7 +183,7 @@ public function retryFailedAction() { $count = $this->resque->retryFailedJobs(); - $this->addFlash('info', 'Retry '.$count.' failed jobs.'); + $this->addFlash('info', 'Retry ' . $count . ' failed jobs.'); return $this->redirectToRoute('ResqueBundle_homepage'); } @@ -195,7 +195,7 @@ public function retryClearFailedAction() { $count = $this->resque->retryFailedJobs(true); - $this->addFlash('info', 'Retry and clear '.$count.' failed jobs.'); + $this->addFlash('info', 'Retry and clear ' . $count . ' failed jobs.'); return $this->redirectToRoute('ResqueBundle_homepage'); } @@ -207,7 +207,7 @@ public function clearFailedAction() { $count = $this->resque->clearFailedJobs(); - $this->addFlash('info', 'Clear '.$count.' failed jobs.'); + $this->addFlash('info', 'Clear ' . $count . ' failed jobs.'); return $this->redirectToRoute('ResqueBundle_homepage'); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5c911a4..96559d0 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -27,7 +27,7 @@ public function getConfigTreeBuilder() if (method_exists($treeBuilder, 'getRootNode')) { // Symfony 4+ - $root = $treeBuilder->getRootNode(); + $root = $treeBuilder->getRootNode(); } else { // Symfony 3 $root = $treeBuilder->root('resque'); @@ -56,7 +56,7 @@ public function getConfigTreeBuilder() ->arrayNode('auto_retry') ->beforeNormalization() ->ifArray() - ->then(function ($var) { + ->then(function($var) { if (\array_key_exists(0, $var)) { return [$var]; } diff --git a/DependencyInjection/ResqueExtension.php b/DependencyInjection/ResqueExtension.php index 5ebee20..73948f2 100644 --- a/DependencyInjection/ResqueExtension.php +++ b/DependencyInjection/ResqueExtension.php @@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container) $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $container->setParameter('resque.vendor_dir', $config['vendor_dir']); diff --git a/Queue.php b/Queue.php index 797c469..563362b 100644 --- a/Queue.php +++ b/Queue.php @@ -47,7 +47,7 @@ public function getName() */ public function getJobs($start = 0, $stop = -1) { - $jobs = \Resque::redis()->lrange('queue:'.$this->name, $start, $stop); + $jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop); $result = []; foreach ($jobs as $job) { @@ -68,8 +68,8 @@ public function remove() */ public function clear() { - $length = \Resque::redis()->llen('queue:'.$this->name); - \Resque::redis()->del('queue:'.$this->name); + $length = \Resque::redis()->llen('queue:' . $this->name); + \Resque::redis()->del('queue:' . $this->name); return $length; } diff --git a/Resque.php b/Resque.php index f0ba721..b1913bc 100644 --- a/Resque.php +++ b/Resque.php @@ -92,7 +92,7 @@ public function setRedisConfiguration($host, $port, $database, $password = null) ]; if (!isset($password)) { - \Resque::setBackend($host.':'.$port, $database); + \Resque::setBackend($host . ':' . $port, $database); } else { $server = 'redis://:' . $password . '@' . $host . ':' . $port; \Resque::setBackend($server, $database); @@ -263,7 +263,7 @@ public function removeFromTimestamp($at, Job $job) */ public function getQueues() { - return array_map(function ($queue) { + return array_map(function($queue) { return new Queue($queue); }, \Resque::queues()); } @@ -283,7 +283,7 @@ public function getQueue($queue) */ public function getWorkers() { - return array_map(function ($worker) { + return array_map(function($worker) { return new Worker($worker); }, \Resque_Worker::all()); } @@ -293,7 +293,7 @@ public function getWorkers() */ public function getRunningWorkers() { - return array_filter($this->getWorkers(), function (Worker $worker) { + return array_filter($this->getWorkers(), function(Worker $worker) { return null !== $worker->getCurrentJob(); }); } @@ -370,7 +370,7 @@ public function getDelayedJobTimestamps() //TODO: find a more efficient way to do this $out = []; foreach ($timestamps as $timestamp) { - $out[] = [$timestamp, \Resque::redis()->llen('delayed:'.$timestamp)]; + $out[] = [$timestamp, \Resque::redis()->llen('delayed:' . $timestamp)]; } return $out; @@ -391,7 +391,7 @@ public function getNumberOfDelayedJobs() */ public function getJobsForTimestamp($timestamp) { - $jobs = \Resque::redis()->lrange('delayed:'.$timestamp, 0, -1); + $jobs = \Resque::redis()->lrange('delayed:' . $timestamp, 0, -1); $out = []; foreach ($jobs as $job) { $out[] = json_decode($job, true); diff --git a/Worker.php b/Worker.php index 98e818e..3ca38d0 100644 --- a/Worker.php +++ b/Worker.php @@ -43,7 +43,7 @@ public function stop() */ public function getId() { - return (string) $this->worker; + return (string)$this->worker; } /** @@ -51,7 +51,7 @@ public function getId() */ public function getQueues() { - return array_map(function ($queue) { + return array_map(function($queue) { return new Queue($queue); }, $this->worker->queues()); } From 4c3e74d7ef48fcc2cf5736ad3ce4509121d2f2bc Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Fri, 22 Apr 2022 17:34:31 -0400 Subject: [PATCH 08/10] This project IS NO LONGER UNDER ACTIVE development --- README.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index b3b2154..efe6807 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,8 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/resquebundle/resque/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/resquebundle/resque/?branch=master) -**This project IS under ACTIVE development (last major update June 2021)** +**This project IS NO LONGER UNDER ACTIVE development (last major update September 2021) ** + +If you would like to take over maintenance of this project please contact phil@phil-taylor.com - I no longer use the code here in any live project as I moved to Symfony Messenger for my queue needs. # ResqueBundle From 09ae1d5d19e0b69eb888c09a82266d621aa4add3 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Fri, 22 Apr 2022 17:34:53 -0400 Subject: [PATCH 09/10] Update README.markdown --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index efe6807..511c1aa 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/resquebundle/resque/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/resquebundle/resque/?branch=master) -**This project IS NO LONGER UNDER ACTIVE development (last major update September 2021) ** +**This project IS NO LONGER UNDER ACTIVE development (last major update September 2021)** If you would like to take over maintenance of this project please contact phil@phil-taylor.com - I no longer use the code here in any live project as I moved to Symfony Messenger for my queue needs. From 02915444f62205e9d4db6a64160d076406ef3d87 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Tue, 11 Oct 2022 17:39:02 +0100 Subject: [PATCH 10/10] Make it clear that this project is no longer maintained --- README.markdown | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/README.markdown b/README.markdown index 511c1aa..44e9fb7 100644 --- a/README.markdown +++ b/README.markdown @@ -1,34 +1,32 @@ [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/resquebundle/resque/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/resquebundle/resque/?branch=master) -**This project IS NO LONGER UNDER ACTIVE development (last major update September 2021)** +**This project IS NO LONGER UNDER ANY development (last major update September 2021)** + +If you would like to take over maintenance of this project please contact phil@phil-taylor.com - I no longer use the code here in any live project as I moved to [Symfony Messenger](https://symfony.com/doc/current/messenger.html), with Redis. for my own queue needs. + +# If you are using PHP 8 plesae see the `php8` branch for the latest stable release + -If you would like to take over maintenance of this project please contact phil@phil-taylor.com - I no longer use the code here in any live project as I moved to Symfony Messenger for my queue needs. # ResqueBundle ## Compatibiltiy - - For Symfony 5+ / PHP8 please use ResqueBundle v5+ - - For Symfony 4+ please use major series ResqueBundle v3+ and work towards Symfony 5 migration ;-) - - For Symfony 3+ please peg to exact release ResqueBundle v2.0.9+ and think about your decision to even use Symfony 3 ;-) +- For Symfony 5+ please use ResqueBundle v4.0.0+ +- For Symfony 4+ please use major series ResqueBundle v3+ and work towards Symfony 5 migration ;-) +- For Symfony 3+ please peg to exact release ResqueBundle v2.0.9+ and think about your decision to even use Symfony 3 ;-) Note that we dont offer the same b/c promise as symfony itself, but try our hardest to make major versions for major symfony versions. -## Update June 2021 - - - New series 5.x to be Symfony 5.3 and PHP 8 compatible only. - - Return correct command exit statuses - - Catch correct Exceptions and new TypeError Exception - ## Update May 2020 - - Inject ParameterBagInterface instead of directly accessing container in commands and controller - - User kernel.project_dir instead of kernel.root_dir (b/c break!, you need to update your config yml) - - Update Routing controller to use long syntax - - Use `@Bundle` syntax for loading twig templates - - force a minimum of Symfony 4.1.2 for critical security - - Use correct Process function for max compatibility - - Drop Symfony 3.4 support totally, sorry. +- Inject ParameterBagInterface instead of directly accessing container in commands and controller +- User kernel.project_dir instead of kernel.root_dir (b/c break!, you need to update your config yml) +- Update Routing controller to use long syntax +- Use `@Bundle` syntax for loading twig templates +- force a minimum of Symfony 4.1.2 for critical security +- Use correct Process function for max compatibility +- Drop Symfony 3.4 support totally, sorry. ## Update November 2019 @@ -38,23 +36,23 @@ If you are still using Symfony 3 then you MUST peg your composer.json to release The first version of this bundle that is highly compatible with, and activly maintained, is 3.0.0 -If you have used this before, and want to get up to date, then you need to - - upgrade to 3.0.0+ version of this bundle - - use Symfony 4 (im using 4.4.0RC1 at the moment) - - change your Jobs to extend `ResqueBundle\Resque\Job` and not `ContainerAwareJob` - - add `__construct` methods to inject your depenancies - - remove ALL REFERENCES to the container or `getContainer` from your jobs - - Enjoy! +If you have used this before, and want to get up to date, then you need to +- upgrade to 3.0.0+ version of this bundle +- use Symfony 4 (im using 4.4.0RC1 at the moment) +- change your Jobs to extend `ResqueBundle\Resque\Job` and not `ContainerAwareJob` +- add `__construct` methods to inject your depenancies +- remove ALL REFERENCES to the container or `getContainer` from your jobs +- Enjoy! # ResqueBundle History -This is a fork of the BCCResqueBundle as ***that** bundle is no longer being actively maintained. There are a lot of outstanding issues, pull requests and bugs that need to be fixed in that project, with no activity, so we forked it, and will activly support and develop the code further in this repo. +This is a fork of the BCCResqueBundle as ***that** bundle is no longer being actively maintained. There are a lot of outstanding issues, pull requests and bugs that need to be fixed in that project, with no activity, so we forked it, and will activly support and develop the code further in this repo. This is also a rebrand of Mpclarkson\ResqueBundle to place the code under a GitHub Organisation for future proof distributed development **Contributions are welcome** -The resque bundle provides integration of [php-resque](https://github.com/chrisboulton/php-resque/) to Symfony4. +The resque bundle provides integration of [php-resque](https://github.com/chrisboulton/php-resque/) to Symfony4. It is inspired from resque, a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later. ## Features: