Add a restart button in recovery section

This commit is contained in:
Girish Ramakrishnan
2019-12-20 11:18:48 -08:00
parent 3f3ec9ef9a
commit adc078a5cb
5 changed files with 47 additions and 38 deletions

View File

@@ -21,6 +21,7 @@ var ISTATES = {
PENDING_DEBUG: 'pending_debug',
PENDING_START: 'pending_start',
PENDING_STOP: 'pending_stop',
PENDING_RESTART: 'pending_restart',
ERROR: 'error',
INSTALLED: 'installed'
};
@@ -555,25 +556,11 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
};
Client.prototype.restartApp = function (id, callback) {
var that = this;
function waitUntilStopped(callback) {
that.getApp(id, function (error, result) {
if (error) return callback(error);
if (result.runState === 'stopped') return callback();
setTimeout(waitUntilStopped.bind(null, callback), 2000);
});
}
that.stopApp(id, function (error) {
post('/api/v1/apps/' + id + '/start', {}, null, function (error, data, status) {
if (error) return callback(error);
if (status !== 202) return callback(new ClientError(status, data));
waitUntilStopped(function (error) {
if (error) return callback(error);
that.startApp(id, callback);
});
callback(null, data);
});
};

View File

@@ -327,6 +327,7 @@ app.filter('installationStateLabel', function () {
case ISTATES.PENDING_BACKUP: return 'Backing up' + waiting;
case ISTATES.PENDING_START: return 'Starting' + waiting;
case ISTATES.PENDING_STOP: return 'Stopping' + waiting;
case ISTATES.PENDING_RESTART: return 'Restarting' + waiting;
case ISTATES.ERROR: {
if (app.error && app.error.message === 'ETRYAGAIN') return 'DNS Error';
return 'Error';
@@ -363,6 +364,7 @@ app.filter('taskName', function () {
case ISTATES.PENDING_BACKUP: return 'backup';
case ISTATES.PENDING_START: return 'start app';
case ISTATES.PENDING_STOP: return 'stop app';
case ISTATES.PENDING_RESTART: return 'restart app';
default: return installationState || '';
}
};

View File

@@ -127,27 +127,23 @@ app.controller('TerminalController', ['$scope', '$timeout', '$location', 'Client
var appId = $scope.selected.value;
function waitUntilStopped(callback) {
function waitUntilRestarted(callback) {
refreshApp(appId, function (error, result) {
if (error) return callback(error);
if (result.installationState === ISTATES.INSTALLED && result.runState === RSTATES.STOPPED) return callback();
setTimeout(waitUntilStopped.bind(null, callback), 2000);
if (result.installationState === ISTATES.INSTALLED) return callback();
setTimeout(waitUntilRestarted.bind(null, callback), 2000);
});
}
Client.stopApp(appId, function (error) {
if (error) console.error('Failed to stop app.', error);
Client.restartApp(appId, function (error) {
if (error) console.error('Failed to restart app.', error);
waitUntilStopped(function (error) {
if (error) console.error('Failed to get app status.', error);
waitUntilRestarted(function (error) {
if (error) console.error('Failed wait for restart.', error);
Client.startApp(appId, function (error) {
if (error) console.error('Failed to start app.', error);
$scope.restartAppBusy = false;
$scope.appBusy = false;
});
$scope.restartAppBusy = false;
$scope.appBusy = false;
});
});
};