Commit 54abada5 authored by Girish Ramakrishnan's avatar Girish Ramakrishnan

backups: add progressCallback to cleanup funcs

parent f1922660
......@@ -1302,9 +1302,10 @@ function applyBackupRetentionPolicy(backups, policy) {
}
}
function cleanupBackup(backupConfig, backup, callback) {
function cleanupBackup(backupConfig, backup, progressCallback, callback) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof backup, 'object');
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
var backupFilePath = getBackupFilePath(backupConfig, backup.id, backup.format);
......@@ -1329,17 +1330,19 @@ function cleanupBackup(backupConfig, backup, callback) {
}
if (backup.format ==='tgz') {
progressCallback({ message: `${backup.id}: Removing ${backupFilePath}`});
api(backupConfig.provider).remove(backupConfig, backupFilePath, done);
} else {
var events = api(backupConfig.provider).removeDir(backupConfig, backupFilePath);
events.on('progress', function (detail) { debug(`cleanupBackup: ${detail}`); });
events.on('progress', (message) => progressCallback({ message: `${backup.id}: ${message}` }));
events.on('done', done);
}
}
function cleanupAppBackups(backupConfig, referencedAppBackupIds, callback) {
function cleanupAppBackups(backupConfig, referencedAppBackupIds, progressCallback, callback) {
assert.strictEqual(typeof backupConfig, 'object');
assert(Array.isArray(referencedAppBackupIds));
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof callback, 'function');
let removedAppBackupIds = [];
......@@ -1357,10 +1360,10 @@ function cleanupAppBackups(backupConfig, referencedAppBackupIds, callback) {
async.eachSeries(appBackups, function iterator(appBackup, iteratorDone) {
if (appBackup.keepReason) return iteratorDone();
debug('cleanupAppBackups: removing %s', appBackup.id);
progressCallback({ message: `Removing app backup ${appBackup.id}`});
removedAppBackupIds.push(appBackup.id);
cleanupBackup(backupConfig, appBackup, iteratorDone);
cleanupBackup(backupConfig, appBackup, progressCallback, iteratorDone);
}, function () {
debug('cleanupAppBackups: done');
......@@ -1369,8 +1372,9 @@ function cleanupAppBackups(backupConfig, referencedAppBackupIds, callback) {
});
}
function cleanupBoxBackups(backupConfig, auditSource, callback) {
function cleanupBoxBackups(backupConfig, progressCallback, auditSource, callback) {
assert.strictEqual(typeof backupConfig, 'object');
assert.strictEqual(typeof progressCallback, 'function');
assert.strictEqual(typeof auditSource, 'object');
assert.strictEqual(typeof callback, 'function');
......@@ -1404,10 +1408,10 @@ function cleanupBoxBackups(backupConfig, auditSource, callback) {
return iteratorNext();
}
debug('cleanupBoxBackups: removing %s', boxBackup.id);
progressCallback({ message: `Removing box backup ${boxBackup.id}`});
removedBoxBackupIds.push(boxBackup.id);
cleanupBackup(backupConfig, boxBackup, iteratorNext);
cleanupBackup(backupConfig, boxBackup, progressCallback, iteratorNext);
}, function () {
debug('cleanupBoxBackups: done');
......@@ -1480,12 +1484,12 @@ function cleanup(auditSource, progressCallback, callback) {
progressCallback({ percent: 10, message: 'Cleaning box backups' });
cleanupBoxBackups(backupConfig, auditSource, function (error, { removedBoxBackupIds, referencedAppBackupIds }) {
cleanupBoxBackups(backupConfig, progressCallback, auditSource, function (error, { removedBoxBackupIds, referencedAppBackupIds }) {
if (error) return callback(error);
progressCallback({ percent: 40, message: 'Cleaning app backups' });
cleanupAppBackups(backupConfig, referencedAppBackupIds, function (error, removedAppBackupIds) {
cleanupAppBackups(backupConfig, referencedAppBackupIds, progressCallback, function (error, removedAppBackupIds) {
if (error) return callback(error);
progressCallback({ percent: 90, message: 'Cleaning snapshots' });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment