From c501d75592d7929650b81dd93476525926504eff Mon Sep 17 00:00:00 2001 From: Marco Manieri Date: Wed, 29 Jul 2015 12:45:53 +0200 Subject: [PATCH 1/6] Added subcommand enqueue (method already implemented) --- src/Shell/CakeResqueShell.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Shell/CakeResqueShell.php b/src/Shell/CakeResqueShell.php index 665cad5..be35276 100644 --- a/src/Shell/CakeResqueShell.php +++ b/src/Shell/CakeResqueShell.php @@ -316,6 +316,9 @@ public function getOptionParser() ]) ->addSubcommand('load', [ 'help' => __d('cake_resque', 'Load a set of predefined workers.'), + ]) + ->addSubcommand('enqueue', [ + 'help' => __d('cake_resque', 'Enqueue a job.'), ]); } From 4ea61702e5bca8fe221114664202780db3918676 Mon Sep 17 00:00:00 2001 From: Marco Manieri Date: Wed, 29 Jul 2015 12:47:59 +0200 Subject: [PATCH 2/6] fixed gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3f25141..f171a7f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ /composer.phar /node_modules/ /build/ -/.idea/ \ No newline at end of file +/.idea/ +src/tmp/* +!src/tmp/empty \ No newline at end of file From a32504ecf05c49ce6a881ab591f4718e2339a912 Mon Sep 17 00:00:00 2001 From: Marco Manieri Date: Wed, 29 Jul 2015 13:29:49 +0200 Subject: [PATCH 3/6] Resque_Job_Creator Patched for cakePHP3: - Resque_Job_Creator cannot be in namespace CakeResque in order to be found by Resque_Job->getIntance; - so in CakeResqueBootstrap we `require Resque_Job_Creator.php` insetad of trying autoload with `use CakeResque/Resque_Job_Creator`; - self::$rootFolder correctly points to src - $model (Shell class) is now properly namespaced (App\Shell) - removed perform method search, replaced returning the method to invoke (runCommand) as well as the class instance as an array Removed bootstrap_config since CakePHP 3 no longer supports arrays of files as plugin bootstrap value (to init CakeResque with values different from defaults plugin must be loaded with no bootstrap enabled and then CakeResque::init must be called with the config values) Improved Exceptions messages: - explicit being thrown by Resque_Job_Creator - diffrentiate between file not found and class not found in file --- config/bootstrap_config.php | 37 ------------------------------------- src/CakeResqueBootstrap.php | 2 +- src/Resque_Job_Creator.php | 18 ++++++------------ 3 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 config/bootstrap_config.php diff --git a/config/bootstrap_config.php b/config/bootstrap_config.php deleted file mode 100644 index 94ab521..0000000 --- a/config/bootstrap_config.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @copyright Copyright 2012, Ber Clausen - * @link http://cakeresque.kamisama.me - * @package CakeResque - * @subpackage CakeResque.Config - * @since 3.4.0 - * @license MIT License (http://www.opensource.org/licenses/mit-license.php) - */ - -/** - * Bootstrap configuration file. - * - * It is intended to ease bootstrapping CakeResque with a custom configuration. - * - * CakePlugin::load('CakeResque', array('bootstrap' => ['bootstrap_config', '../../../Config/cakeresque', 'bootstrap'])); - * - * Where '../../../Config/cakeresque' indicates the path to the App's custom configuration file: - * - * // APP/Config/cakeresque.php - * Configure::write('CakeResque.Redis.host', 'my_hostname'); - * - * @see CakeResque::init(), CakeResque::loadConfig(). - */ -Configure::load('CakeResque.config'); diff --git a/src/CakeResqueBootstrap.php b/src/CakeResqueBootstrap.php index 6d98897..019c8e4 100644 --- a/src/CakeResqueBootstrap.php +++ b/src/CakeResqueBootstrap.php @@ -20,7 +20,7 @@ */ use Cake\Console\ShellDispatcher; use Cake\Console\Shell; -use CakeResque\Resque_Job_Creator; +REQUIRE 'Resque_Job_Creator.php'; define('APP', getenv('APP')); diff --git a/src/Resque_Job_Creator.php b/src/Resque_Job_Creator.php index f4affca..cb9fce6 100644 --- a/src/Resque_Job_Creator.php +++ b/src/Resque_Job_Creator.php @@ -1,7 +1,4 @@ Date: Thu, 30 Jul 2015 17:17:55 +0200 Subject: [PATCH 4/6] Final patches for cakePHP 3 - Resque_Job_Creator.php is no longer needed, Resque_Job_Creator is defined in CakeResqueBootstrap.php - Resque_Job_Creator does not need to inspect anything since everything is nicely handled by the Cake\Console\ShellDispatcher->dispatch method - the args list must mock the 0th element from cli (file name: 'void') --- src/CakeResqueBootstrap.php | 28 +++++++++++++--- src/Resque_Job_Creator.php | 65 ------------------------------------- 2 files changed, 24 insertions(+), 69 deletions(-) delete mode 100644 src/Resque_Job_Creator.php diff --git a/src/CakeResqueBootstrap.php b/src/CakeResqueBootstrap.php index 019c8e4..7932a4b 100644 --- a/src/CakeResqueBootstrap.php +++ b/src/CakeResqueBootstrap.php @@ -18,10 +18,30 @@ * @since 0.5 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +define('APP', getenv('APP')); +include APP . '../config/bootstrap.php'; use Cake\Console\ShellDispatcher; -use Cake\Console\Shell; -REQUIRE 'Resque_Job_Creator.php'; -define('APP', getenv('APP')); +class Resque_Job_Creator +{ + + /** + * Create and return a job instance + * + * @param string $className className of the job to instanciate + * @param array $args Array of method name and arguments used to build the job + * @return object $args a job instance + * @throws Resque_Exception when the class is not found, or does not follow the job file convention + */ + public static function createJob($className, $args) + { + if (!class_exists('Cake\Console\ShellDispatcher')) { + throw new Resque_Exception('Resque_Job_Creator could not find Cake\Console\ShellDispatcher.'); + } + + array_unshift($args, 'void', $className); + + return [new Cake\Console\ShellDispatcher($args),'dispatch']; -new ShellDispatcher($argv); + } +} \ No newline at end of file diff --git a/src/Resque_Job_Creator.php b/src/Resque_Job_Creator.php deleted file mode 100644 index cb9fce6..0000000 --- a/src/Resque_Job_Creator.php +++ /dev/null @@ -1,65 +0,0 @@ - Date: Fri, 31 Jul 2015 17:16:06 +0200 Subject: [PATCH 5/6] - APP is defined in CakePHP bootstrap, so we just use the ENV variable to locate CakePHP bootstrap itself - The Job will be run with the Cake Console switch -q to avoid cluttering log files --- src/CakeResqueBootstrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CakeResqueBootstrap.php b/src/CakeResqueBootstrap.php index 7932a4b..c618bf3 100644 --- a/src/CakeResqueBootstrap.php +++ b/src/CakeResqueBootstrap.php @@ -18,8 +18,7 @@ * @since 0.5 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -define('APP', getenv('APP')); -include APP . '../config/bootstrap.php'; +include getenv('APP') . '../config/bootstrap.php'; use Cake\Console\ShellDispatcher; class Resque_Job_Creator @@ -40,6 +39,7 @@ public static function createJob($className, $args) } array_unshift($args, 'void', $className); + $args[] = '-q'; return [new Cake\Console\ShellDispatcher($args),'dispatch']; From d7a6d5a1e1e93bd4324a6bf3b11b528a68993117 Mon Sep 17 00:00:00 2001 From: Marco Manieri Date: Fri, 31 Jul 2015 17:17:55 +0200 Subject: [PATCH 6/6] when ResqueScheduler->nextDelayedTimestamp is invoked from CakeResqueShell->stats it needs to look for the next job to be executed, "future" included. --- src/Shell/CakeResqueShell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shell/CakeResqueShell.php b/src/Shell/CakeResqueShell.php index be35276..7dfdc82 100644 --- a/src/Shell/CakeResqueShell.php +++ b/src/Shell/CakeResqueShell.php @@ -1273,7 +1273,7 @@ public function stats() $this->out("\t - " . __d('cake_resque', 'Delayed Jobs') . " : " . $delayedJobCount); if ($delayedJobCount > 0) { - $this->out("\t - " . __d('cake_resque', 'Next Job on') . " : " . strftime('%a %b %d %H:%M:%S %Z %Y', $schedulerWorker->nextDelayedTimestamp())); + $this->out("\t - " . __d('cake_resque', 'Next Job on') . " : " . strftime('%a %b %d %H:%M:%S %Z %Y', $schedulerWorker->nextDelayedTimestamp(null,true))); } } $this->out("\n");