MDL-25811 automated backups - clean running status after 90 mins of inactivity

This commit is contained in:
Eloy Lafuente (stronk7) 2011-06-18 17:21:15 +02:00
parent 3552484b91
commit beae4a6684

View file

@ -76,7 +76,7 @@ abstract class backup_cron_automated_helper {
} else if ($state === backup_cron_automated_helper::STATE_RUNNING) { } else if ($state === backup_cron_automated_helper::STATE_RUNNING) {
mtrace('RUNNING'); mtrace('RUNNING');
if ($rundirective == self::RUN_IMMEDIATELY) { if ($rundirective == self::RUN_IMMEDIATELY) {
mtrace('automated backups are already. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.'); mtrace('Automated backups are already running. If this script is being run by cron this constitues an error. You will need to increase the time between executions within cron.');
} else { } else {
mtrace("automated backup are already running. Execution delayed"); mtrace("automated backup are already running. Execution delayed");
} }
@ -401,10 +401,19 @@ abstract class backup_cron_automated_helper {
if ($active === self::AUTO_BACKUP_DISABLED || ($rundirective == self::RUN_ON_SCHEDULE && $active === self::AUTO_BACKUP_MANUAL)) { if ($active === self::AUTO_BACKUP_DISABLED || ($rundirective == self::RUN_ON_SCHEDULE && $active === self::AUTO_BACKUP_MANUAL)) {
return self::STATE_DISABLED; return self::STATE_DISABLED;
} else if (!empty($config->backup_auto_running)) { } else if (!empty($config->backup_auto_running)) {
// TODO: We should find some way of checking whether the automated // Detect if the backup_auto_running semaphore is a valid one
// backup has infact finished. In 1.9 this was being done by checking // by looking for recent activity in the backup_controllers table
// the log entries. // for backups of type backup::MODE_AUTOMATED
return self::STATE_RUNNING; $timetosee = 60 * 90; // Time to consider in order to clean the semaphore
$params = array( 'purpose' => backup::MODE_AUTOMATED, 'timetolook' => (time() - $timetosee));
if ($DB->record_exists_select('backup_controllers',
"operation = 'backup' AND type = 'course' AND purpose = :purpose AND timemodified > :timetolook", $params)) {
return self::STATE_RUNNING; // Recent activity found, still running
} else {
// No recent activity found, let's clean the semaphore
mtrace('Automated backups activity not found in last ' . (int)$timetosee/60 . ' minutes. Cleaning running status');
backup_cron_automated_helper::set_state_running(false);
}
} }
return self::STATE_OK; return self::STATE_OK;
} }