Use task API in app backup
This commit is contained in:
@@ -62,8 +62,6 @@ var COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd.config.ejs', {
|
||||
LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }),
|
||||
CONFIGURE_LOGROTATE_CMD = path.join(__dirname, 'scripts/configurelogrotate.sh');
|
||||
|
||||
var NOOP_CALLBACK = function (error) { if (error) debug(error); };
|
||||
|
||||
function initialize(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
@@ -576,7 +574,9 @@ function install(app, progressCallback, callback) {
|
||||
progressCallback.bind(null, { percent: 65, message: 'Download backup and restoring addons' }),
|
||||
addons.setupAddons.bind(null, app, app.manifest.addons),
|
||||
addons.clearAddons.bind(null, app, app.manifest.addons),
|
||||
backups.restoreApp.bind(null, app, app.manifest.addons, restoreConfig, (progress) => updateApp(app, { installationProgress: `65, Restore - ${progress.message}` }, NOOP_CALLBACK))
|
||||
backups.restoreApp.bind(null, app, app.manifest.addons, restoreConfig, (progress) => {
|
||||
progressCallback({ percent: 65, message: `Restore - ${progress.message}` });
|
||||
})
|
||||
], next);
|
||||
}
|
||||
},
|
||||
@@ -609,23 +609,23 @@ function install(app, progressCallback, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function backup(app, callback) {
|
||||
function backup(app, progressCallback, callback) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof progressCallback, 'function');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
async.series([
|
||||
updateApp.bind(null, app, { installationProgress: '10, Backing up' }),
|
||||
backups.backupApp.bind(null, app, { /* options */ }, (progress) => updateApp(app, { installationProgress: `30, ${progress.message}` }, NOOP_CALLBACK)),
|
||||
progressCallback.bind(null, { percent: 10, message: 'Backing up' }),
|
||||
backups.backupApp.bind(null, app, { /* options */ }, (progress) => {
|
||||
progressCallback({ percent: 30, message: progress.message });
|
||||
}),
|
||||
|
||||
// done!
|
||||
function (callback) {
|
||||
debugApp(app, 'installed');
|
||||
updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '' }, callback);
|
||||
}
|
||||
progressCallback.bind(null, { percent: 100, message: 'Done' }),
|
||||
updateApp.bind(null, app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: '', taskId: null })
|
||||
], function seriesDone(error) {
|
||||
if (error) {
|
||||
debugApp(app, 'error backing up app: %s', error);
|
||||
return updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: error.message }, callback.bind(null, error)); // return to installed state intentionally
|
||||
return updateApp(app, { installationState: appdb.ISTATE_INSTALLED, installationProgress: error.message, taskId: null }, callback.bind(null, error)); // return to installed state intentionally
|
||||
}
|
||||
callback(null);
|
||||
});
|
||||
@@ -737,7 +737,9 @@ function update(app, progressCallback, callback) {
|
||||
async.series([
|
||||
progressCallback.bind(null, { percent: 15, message: 'Backing up app' }),
|
||||
// preserve update backups for 3 weeks
|
||||
backups.backupApp.bind(null, app, { preserveSecs: 3*7*24*60*60 }, (progress) => updateApp(app, { installationProgress: `15, Backup - ${progress.message}` }, NOOP_CALLBACK))
|
||||
backups.backupApp.bind(null, app, { preserveSecs: 3*7*24*60*60 }, (progress) => {
|
||||
progressCallback({ percent: 15, message: `Backup - ${progress.message}` });
|
||||
})
|
||||
], function (error) {
|
||||
if (error) error.backupError = true;
|
||||
next(error);
|
||||
@@ -968,6 +970,7 @@ function run(appId, progressCallback, callback) {
|
||||
case appdb.ISTATE_PENDING_RESTORE: return install(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_UPDATE: return update(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_FORCE_UPDATE: return update(app, progressCallback, callback);
|
||||
case appdb.ISTATE_PENDING_BACKUP: return backup(app, progressCallback, callback);
|
||||
|
||||
default:
|
||||
debugApp(app, 'apptask launched with invalid command');
|
||||
|
||||
Reference in New Issue
Block a user