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 1, 2016
2 parents 9a74722 + 27c76b2 commit e5a6cbb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ Features
- Cancel running tasks
- 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.

To run pending tasks just run

```
./craft/app/etc/console/yiic taskmanager run
```

To watch for pending tasks and them run them, run

```
./craft/app/etc/console/yiic taskmanager watch
```

Development
=================
Expand All @@ -22,6 +35,9 @@ phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/

Changelog
=================
###0.4.0###
- Added the ability to run and watch for tasks via the command line.

###0.3.1###
- Updated the plugin for Craft 2.5
- The hook "modifyTaskManagerAttributes" is now "defineAdditionalTaskManagerTableAttributes"
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.3.1';
return '0.4.0';
}

/**
Expand Down
89 changes: 89 additions & 0 deletions consolecommands/TaskManagerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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
*/
class TaskManagerCommand extends BaseCommand
{
/**
* Runs pending tasks.
*
* @return int
*/
public function actionRun()
{
Craft::log(Craft::t('Running new tasks.'));

// Make sure tasks aren't already running
if (!craft()->tasks->isTaskRunning()) {

// 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;
}

/**
* Watch for tasks and run them.
*/
public function actionWatch()
{
Craft::log(Craft::t('Watching for new tasks.'));

// 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()) {

// 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.'));
}

// Sleep a little
sleep(10);
}
}

/**
* Reset craft next pending task cache using reflection.
*/
private function resetCraftNextPendingTasksCache()
{
$obj = craft()->tasks;
$refObject = new \ReflectionObject($obj);
$refProperty = $refObject->getProperty('_nextPendingTask');
$refProperty->setAccessible(true);
$refProperty->setValue($obj, null);
}
}

0 comments on commit e5a6cbb

Please sign in to comment.