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 Apr 6, 2016
2 parents e5a6cbb + 236506a commit e2d0567
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 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.0';
return '0.4.1';
}

/**
Expand Down
21 changes: 21 additions & 0 deletions config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Craft;

/**
* Task Manager.
*
* @author Bob Olde Hampsink <[email protected]>
* @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
);
42 changes: 8 additions & 34 deletions consolecommands/TaskManagerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -52,26 +38,14 @@ 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);
sleep(craft()->config->get('taskInterval'));
}
}

Expand Down

0 comments on commit e2d0567

Please sign in to comment.