diff --git a/README.md b/README.md index e159724..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 @@ -35,6 +36,10 @@ 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### - Fixed bug with reading default config values diff --git a/TaskManagerPlugin.php b/TaskManagerPlugin.php index fc86446..31796da 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'; } /** @@ -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 e3485f8..e64ebb4 100644 --- a/config.php +++ b/config.php @@ -1,7 +1,5 @@ 0, // At what interval should the watcher watch for new tasks? (in seconds) - 'taskInterval' => 10 + 'taskInterval' => 10, + + // Hirefire.io token + 'hirefireToken' => getenv('HIREFIRE_TOKEN'), + + // Name of the task worker you're using (if using Heroku + Hirefire.io) + 'hirefireWorker' => 'worker', ); 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')); } diff --git a/controllers/TaskManagerController.php b/controllers/TaskManagerController.php index 62868e3..a8ea72c 100644 --- a/controllers/TaskManagerController.php +++ b/controllers/TaskManagerController.php @@ -20,6 +20,27 @@ class TaskManagerController extends BaseController */ public $allowAnonymous = true; + /** + * Get pending tasks in Hirefire.io format + * + * @param array $variables + * + * @throws HttpException + */ + public function actionGetPendingTasks(array $variables = array()) + { + // 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(), + ))); + } + /** * Rerun all failed tasks. */