From bbc608f1ed53818e1dff7aee99d22d817e56ed89 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Mon, 4 Apr 2016 15:44:47 +0200 Subject: [PATCH 1/2] Simplified the running of tasks --- consolecommands/TaskManagerCommand.php | 40 +++++--------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/consolecommands/TaskManagerCommand.php b/consolecommands/TaskManagerCommand.php index 262a236..e749ac0 100644 --- a/consolecommands/TaskManagerCommand.php +++ b/consolecommands/TaskManagerCommand.php @@ -22,24 +22,10 @@ public function actionRun() { Craft::log(Craft::t('Running new tasks.')); - // Make sure tasks aren't already running - if (!craft()->tasks->isTaskRunning()) { + // Start running tasks + craft()->tasks->runPendingTasks(); - // Is there a pending task? - if (craft()->tasks->getNextPendingTask()) { - - // Start running tasks - craft()->tasks->runPendingTasks(); - - return 1; - } else { - Craft::log(Craft::t('No pending tasks found.')); - } - } else { - Craft::log(Craft::t('Tasks are already running.')); - } - - return 0; + return 1; } /** @@ -52,23 +38,11 @@ public function actionWatch() // Keep on checking for pending tasks while (true) { - // Make sure tasks aren't already running - if (!craft()->tasks->isTaskRunning()) { - - // Reset next pending tasks cache - $this->resetCraftNextPendingTasksCache(); - - // Is there a pending task? - if (craft()->tasks->getNextPendingTask()) { + // Reset next pending tasks cache + $this->resetCraftNextPendingTasksCache(); - // Start running tasks - craft()->tasks->runPendingTasks(); - } else { - Craft::log(Craft::t('No pending tasks found.')); - } - } else { - Craft::log(Craft::t('Tasks are already running, skipping iteration.')); - } + // Start running tasks + craft()->tasks->runPendingTasks(); // Sleep a little sleep(10); From 236506a252da6fc094734ee8de2d39471e7bbcff Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Mon, 4 Apr 2016 15:51:27 +0200 Subject: [PATCH 2/2] Added the ability to control the watch interval --- README.md | 3 +++ TaskManagerPlugin.php | 2 +- config.php | 21 +++++++++++++++++++++ consolecommands/TaskManagerCommand.php | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 config.php diff --git a/README.md b/README.md index 0ae7e98..5db2a1b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/ Changelog ================= +###0.4.1### + - Added the ability to control the watch interval via the `taskInterval` config setting + ###0.4.0### - Added the ability to run and watch for tasks via the command line. diff --git a/TaskManagerPlugin.php b/TaskManagerPlugin.php index 35f2be4..6a463e1 100644 --- a/TaskManagerPlugin.php +++ b/TaskManagerPlugin.php @@ -40,7 +40,7 @@ public function getDescription() */ public function getVersion() { - return '0.4.0'; + return '0.4.1'; } /** diff --git a/config.php b/config.php new file mode 100644 index 0000000..e3485f8 --- /dev/null +++ b/config.php @@ -0,0 +1,21 @@ + + * @copyright Copyright (c) 2015, Bob Olde Hampsink + * @license MIT + * + * @link http://github.com/boboldehampsink + */ +return array( + + // How long should we wait before we forfeit a task as hanging? + 'taskTimeout' => 0, + + // At what interval should the watcher watch for new tasks? (in seconds) + 'taskInterval' => 10 +); diff --git a/consolecommands/TaskManagerCommand.php b/consolecommands/TaskManagerCommand.php index e749ac0..d5e3229 100644 --- a/consolecommands/TaskManagerCommand.php +++ b/consolecommands/TaskManagerCommand.php @@ -45,7 +45,7 @@ public function actionWatch() craft()->tasks->runPendingTasks(); // Sleep a little - sleep(10); + sleep(craft()->config->get('taskInterval')); } }