MDL-38190 (2) Backup/restore: Progress tracking for tasks and steps

This commit is contained in:
sam marshall
2013-08-16 10:50:36 +01:00
parent 16cd708835
commit 2531ae2922
3 changed files with 41 additions and 0 deletions
+23
View File
@@ -67,6 +67,17 @@ abstract class base_task implements checksumable, executable, loggable {
return $this->settings;
}
/**
* Returns the weight of this task, an approximation of the amount of time
* it will take. By default this value is 1. It can be increased for longer
* tasks.
*
* @return int Weight
*/
public function get_weight() {
return 1;
}
public function get_setting($name) {
// First look in task settings
$result = null;
@@ -159,6 +170,13 @@ abstract class base_task implements checksumable, executable, loggable {
if ($this->executed) {
throw new base_task_exception('base_task_already_executed', $this->name);
}
// Starts progress based on the weight of this task and number of steps.
$progress = $this->get_progress();
$progress->start_progress($this->get_name(), count($this->steps), $this->get_weight());
$done = 0;
// Execute all steps.
foreach ($this->steps as $step) {
$result = $step->execute();
// If step returns array, it will be forwarded to plan
@@ -166,11 +184,16 @@ abstract class base_task implements checksumable, executable, loggable {
if (is_array($result) and !empty($result)) {
$this->add_result($result);
}
$done++;
$progress->progress($done);
}
// Mark as executed if any step has been executed
if (!empty($this->steps)) {
$this->executed = true;
}
// Finish progress for this task.
$progress->end_progress();
}
/**