Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Olde Hampsink committed Jul 4, 2016
2 parents 73ee9be + c76ae24 commit b76af49
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
14 changes: 13 additions & 1 deletion TaskManagerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function getDescription()
*/
public function getVersion()
{
return '0.4.2';
return '0.4.3';
}

/**
Expand Down Expand Up @@ -82,4 +82,16 @@ public function hasCpSection()
{
return true;
}

/**
* Register hirefire endpoint
*
* @return array
*/
public function registerSiteRoutes()
{
return array(
'hirefire/(?P<token>(.*?))/info' => array('action' => 'taskManager/getPendingTasks'),
);
}
}
10 changes: 7 additions & 3 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

namespace Craft;

/**
* Task Manager.
*
Expand All @@ -17,5 +15,11 @@
'taskTimeout' => 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',
);
6 changes: 6 additions & 0 deletions consolecommands/TaskManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
21 changes: 21 additions & 0 deletions controllers/TaskManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit b76af49

Please sign in to comment.