Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2015-06-23 15:55:14 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2015-06-24 22:22:01 +0300
commitb1df4aa23693096e0c3cbb479b71b8cb1d4ddb4a (patch)
tree4eab272573ed90a6c327cae75868a6958bc0be0b /core/Scheduler
parent444712509c614f92cdd5a62a079ac3405c611a4b (diff)
The command `scheduled-tasks:run` now allows to run a single task
Diffstat (limited to 'core/Scheduler')
-rw-r--r--core/Scheduler/Scheduler.php61
1 files changed, 48 insertions, 13 deletions
diff --git a/core/Scheduler/Scheduler.php b/core/Scheduler/Scheduler.php
index 4080cc89d1..86b8f44614 100644
--- a/core/Scheduler/Scheduler.php
+++ b/core/Scheduler/Scheduler.php
@@ -121,17 +121,7 @@ class Scheduler
}
if ($shouldExecuteTask) {
- $this->logger->info("Scheduler: executing task {taskName}...", array('taskName' => $taskName));
-
- $timer = new Timer();
-
- $this->isRunningTask = true;
$message = $this->executeTask($task);
- $this->isRunningTask = false;
-
- $this->logger->info("Scheduler: finished. {timeElapsed}", array(
- 'taskName' => $taskName, 'timeElapsed' => $timer
- ));
$executionResults[] = array('task' => $taskName, 'output' => $message);
}
@@ -144,6 +134,25 @@ class Scheduler
}
/**
+ * Run a specific task now. Will ignore the schedule completely.
+ *
+ * @param string $taskName
+ * @return string Task output.
+ */
+ public function runTaskNow($taskName)
+ {
+ $tasks = $this->loader->loadTasks();
+
+ foreach ($tasks as $task) {
+ if ($task->getName() === $taskName) {
+ return $this->executeTask($task);
+ }
+ }
+
+ throw new \InvalidArgumentException('Task ' . $taskName . ' not found');
+ }
+
+ /**
* Determines a task's scheduled time and persists it, overwriting the previous scheduled time.
*
* Call this method if your task's scheduled time has changed due to, for example, an option that
@@ -184,6 +193,20 @@ class Scheduler
}
/**
+ * Returns the list of the task names.
+ *
+ * @return string[]
+ */
+ public function getTaskList()
+ {
+ $tasks = $this->loader->loadTasks();
+
+ return array_map(function (Task $task) {
+ return $task->getName();
+ }, $tasks);
+ }
+
+ /**
* Executes the given task
*
* @param Task $task
@@ -191,16 +214,28 @@ class Scheduler
*/
private function executeTask($task)
{
- $this->logger->debug('Running task {task}', array('task' => $task->getName()));
+ $this->logger->info("Scheduler: executing task {taskName}...", array(
+ 'taskName' => $task->getName(),
+ ));
+
+ $this->isRunningTask = true;
+
+ $timer = new Timer();
try {
- $timer = new Timer();
- call_user_func(array($task->getObjectInstance(), $task->getMethodName()), $task->getMethodParameter());
+ $callable = array($task->getObjectInstance(), $task->getMethodName());
+ call_user_func($callable, $task->getMethodParameter());
$message = $timer->__toString();
} catch (Exception $e) {
$message = 'ERROR: ' . $e->getMessage();
}
+ $this->isRunningTask = false;
+
+ $this->logger->info("Scheduler: finished. {timeElapsed}", array(
+ 'timeElapsed' => $timer,
+ ));
+
return $message;
}
}