for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?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.'));
// Start running tasks
craft()->tasks->runPendingTasks();
return 1;
}
* 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) {
// Reset next pending tasks cache
$this->resetCraftNextPendingTasksCache();
// Sleep a little
sleep(craft()->config->get('taskInterval'));
* 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);