Skip to content
Extraits de code Groupes Projets
Valider 8ffa6ba4 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

added new events for scheduled tasks

parent 33d0ae18
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -4,6 +4,11 @@ This is the Developer Changelog for Piwik platform developers. All changes in ou
The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** lets you see more details about any Piwik release, such as the list of new guides and FAQs, security fixes, and links to all closed issues.
## Piwik 3.0.5
### New APIs
* The events `ScheduledTasks.shouldExecuteTask`, `ScheduledTasks.execute`, `ScheduledTasks.execute.end` have been added to customize the behaviour of scheduled tasks.
## Piwik 3.0.4
### New APIs
......
......@@ -9,6 +9,7 @@
namespace Piwik\Scheduler;
use Exception;
use Piwik\Piwik;
use Piwik\Timer;
use Psr\Log\LoggerInterface;
......@@ -120,6 +121,17 @@ class Scheduler
$this->logger->debug("Task {task} is scheduled to run again for {date}.", array('task' => $taskName, 'date' => $rescheduledDate));
}
/**
* Triggered before a task is executed.
*
* A plugin can listen to it and modify whether a specific task should be executed or not. This way
* you can force certain tasks to be executed more often or for example to be never executed.
*
* @param bool &$shouldExecuteTask Decides whether the task will be executed.
* @param Task $task The task that is about to be executed.
*/
Piwik::postEvent('ScheduledTasks.shouldExecuteTask', array(&$shouldExecuteTask, $task));
if ($shouldExecuteTask) {
$message = $this->executeTask($task);
......@@ -222,6 +234,13 @@ class Scheduler
$timer = new Timer();
/**
* Triggered directly before a scheduled task is executed
*
* @param Task $task The task that is about to be executed
*/
Piwik::postEvent('ScheduledTasks.execute', array(&$task));
try {
$callable = array($task->getObjectInstance(), $task->getMethodName());
call_user_func($callable, $task->getMethodParameter());
......@@ -232,6 +251,16 @@ class Scheduler
$this->isRunningTask = false;
/**
* Triggered after a scheduled task is successfully executed.
*
* You can use the event to execute for example another task whenever a specific task is executed or to clean up
* certain resources.
*
* @param Task $task The task that was just executed
*/
Piwik::postEvent('ScheduledTasks.execute.end', array(&$task));
$this->logger->info("Scheduler: finished. {timeElapsed}", array(
'timeElapsed' => $timer,
));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter