From d445bad697e0873ac190fdaad0ebaf0c2d39afeb Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Wed, 13 Apr 2016 08:40:40 +0200 Subject: [PATCH 1/6] Recycle db connection --- README.md | 3 +++ TaskManagerPlugin.php | 2 +- consolecommands/TaskManagerCommand.php | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e159724..99df95d 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/ Changelog ================= +###0.4.3### + - Recycle db connection + ###0.4.2### - Fixed bug with reading default config values diff --git a/TaskManagerPlugin.php b/TaskManagerPlugin.php index fc86446..9b58a42 100644 --- a/TaskManagerPlugin.php +++ b/TaskManagerPlugin.php @@ -40,7 +40,7 @@ public function getDescription() */ public function getVersion() { - return '0.4.2'; + return '0.4.3'; } /** diff --git a/consolecommands/TaskManagerCommand.php b/consolecommands/TaskManagerCommand.php index beefef0..4543ca7 100644 --- a/consolecommands/TaskManagerCommand.php +++ b/consolecommands/TaskManagerCommand.php @@ -38,12 +38,18 @@ public function actionWatch() // Keep on checking for pending tasks while (true) { + // Open db connection, if closed + craft()->db->setActive(true); + // Reset next pending tasks cache $this->resetCraftNextPendingTasksCache(); // Start running tasks craft()->tasks->runPendingTasks(); + // Close db connection, if open + craft()->db->setActive(false); + // Sleep a little sleep(craft()->config->get('taskInterval', 'taskManager')); } From d6d1ef986dc216742639a8e74ab62cfa9698d553 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Wed, 13 Apr 2016 15:07:14 +0200 Subject: [PATCH 2/6] Remove namespace from config --- config.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/config.php b/config.php index e3485f8..36a2932 100644 --- a/config.php +++ b/config.php @@ -1,7 +1,5 @@ Date: Wed, 1 Jun 2016 08:50:27 +0200 Subject: [PATCH 3/6] Added the ability to get pending tasks in Hirefire.io format --- README.md | 1 + config.php | 5 ++++- controllers/TaskManagerController.php | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99df95d..4af5048 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/ Changelog ================= ###0.4.3### + - Added the ability to get pending tasks in Hirefire.io format - Recycle db connection ###0.4.2### diff --git a/config.php b/config.php index 36a2932..62093ca 100644 --- a/config.php +++ b/config.php @@ -15,5 +15,8 @@ 'taskTimeout' => 0, // At what interval should the watcher watch for new tasks? (in seconds) - 'taskInterval' => 10 + 'taskInterval' => 10, + + // Name of the task worker you're using (if using Heroku + Hirefire.io) + 'taskWorker' => 'worker', ); diff --git a/controllers/TaskManagerController.php b/controllers/TaskManagerController.php index 62868e3..b3cabbd 100644 --- a/controllers/TaskManagerController.php +++ b/controllers/TaskManagerController.php @@ -20,6 +20,17 @@ class TaskManagerController extends BaseController */ public $allowAnonymous = true; + /** + * Get pending tasks in Hirefire.io format + */ + public function actionGetPendingTasks() + { + $this->returnJson(array( + 'name' => craft()->config->get('taskWorker', 'taskManager'), + 'quantity' => craft()->tasks->getTotalTasks(), + )); + } + /** * Rerun all failed tasks. */ From 537d165489d4c1370c3c0b72ec5ddbdff084e1cf Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Wed, 1 Jun 2016 09:08:43 +0200 Subject: [PATCH 4/6] Register hirefire endpoint with token --- TaskManagerPlugin.php | 12 ++++++++++++ config.php | 5 ++++- controllers/TaskManagerController.php | 18 ++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/TaskManagerPlugin.php b/TaskManagerPlugin.php index 9b58a42..ea4bc3f 100644 --- a/TaskManagerPlugin.php +++ b/TaskManagerPlugin.php @@ -82,4 +82,16 @@ public function hasCpSection() { return true; } + + /** + * Register hirefire endpoint + * + * @return array + */ + public function registerSiteRoutes() + { + return array( + 'hirefire/(?P(.*?)/info' => array('action' => 'taskManager/getPendingTasks'), + ); + } } diff --git a/config.php b/config.php index 62093ca..e64ebb4 100644 --- a/config.php +++ b/config.php @@ -17,6 +17,9 @@ // At what interval should the watcher watch for new tasks? (in seconds) 'taskInterval' => 10, + // Hirefire.io token + 'hirefireToken' => getenv('HIREFIRE_TOKEN'), + // Name of the task worker you're using (if using Heroku + Hirefire.io) - 'taskWorker' => 'worker', + 'hirefireWorker' => 'worker', ); diff --git a/controllers/TaskManagerController.php b/controllers/TaskManagerController.php index b3cabbd..a8ea72c 100644 --- a/controllers/TaskManagerController.php +++ b/controllers/TaskManagerController.php @@ -22,13 +22,23 @@ class TaskManagerController extends BaseController /** * Get pending tasks in Hirefire.io format + * + * @param array $variables + * + * @throws HttpException */ - public function actionGetPendingTasks() + public function actionGetPendingTasks(array $variables = array()) { - $this->returnJson(array( - 'name' => craft()->config->get('taskWorker', 'taskManager'), + // Verify hirefire token + if ($variables['token'] != craft()->config->get('hirefireToken', 'taskManager')) { + throw new HttpException(400, Craft::t('Invalid Hirefire token.')); + } + + // Return pending tasks for worker + $this->returnJson(array(array( + 'name' => craft()->config->get('hirefireWorker', 'taskManager'), 'quantity' => craft()->tasks->getTotalTasks(), - )); + ))); } /** From d934b8771151b0881d131a9fd643490d3eea7045 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Wed, 1 Jun 2016 09:09:21 +0200 Subject: [PATCH 5/6] Updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4af5048..87cb262 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Features - Rerun running or failed tasks - If you set up a cronjob to run /actions/taskManager/rerunAllFailedTasks, you can automatically rerun failed tasks - Comes with two console commands, one to run pending tasks and one to watch for pending tasks and run them. + - Has an endpoint for Hirefire, see http://support.hirefire.io/help/kb/guides/any-programming-language To run pending tasks just run From c76ae24ff8a830384a35423f38c16a611c447722 Mon Sep 17 00:00:00 2001 From: Bob Olde Hampsink Date: Wed, 1 Jun 2016 09:12:51 +0200 Subject: [PATCH 6/6] Typo in site route regex --- TaskManagerPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TaskManagerPlugin.php b/TaskManagerPlugin.php index ea4bc3f..31796da 100644 --- a/TaskManagerPlugin.php +++ b/TaskManagerPlugin.php @@ -91,7 +91,7 @@ public function hasCpSection() public function registerSiteRoutes() { return array( - 'hirefire/(?P(.*?)/info' => array('action' => 'taskManager/getPendingTasks'), + 'hirefire/(?P(.*?))/info' => array('action' => 'taskManager/getPendingTasks'), ); } }