Another attempt to fix app polling

Using taskId only to update app info leads to various outdated states if
an app task has finished. We need to also update once the task has
finished at least once. So instead of individual app polling, we can
simply rely on the all apps listing api, which we poll anyways and not
rely on the restricted properties in the main apps view.

The app configure will fetch the updated full properties now, not
relying on the Clients internal caching
This commit is contained in:
Johannes Zellner
2020-06-14 13:35:28 +02:00
parent 1960969325
commit 01683e9383
2 changed files with 44 additions and 41 deletions
+43 -39
View File
@@ -1275,6 +1275,32 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
});
};
Client.prototype.getAppWithTask = function (appId, callback) {
var that = this;
this.getApp(appId, function (error, app) {
if (error) return callback(error);
if (!app.taskId) return callback(null, app);
that.getTask(app.taskId, function (error, task) {
if (error) return callback(error);
if (task) {
app.progress = task.percent;
app.message = task.message;
app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes();
} else {
app.progress = 0;
app.message = '';
app.taskMinutesActive = 0;
}
callback(null, app);
});
});
};
Client.prototype.getCachedAppSync = function (appId) {
var appFound = null;
this._installedApps.some(function (app) {
@@ -1758,9 +1784,9 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
// only replace if the app is already known
if (found !== -1 && this._installedApps[found].fqdn === tmp.fqdn) { // app location has not changed
angular.copy(tmp, this._installedApps[found]);
} else if (found !== -1) {
this._installedApps.splice(found, 1); // remove it
} else {
if (found !== -1) this._installedApps.splice(found, 1); // remove it
var loc = binarySearch(this._installedApps, function (item) { return item.fqdn.localeCompare(app.fqdn) <= 0; });
this._installedApps.splice(loc, 0, tmp); // insert into sorted fqdn array
}
@@ -1779,34 +1805,6 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
angular.copy(tmp, this._appTags);
};
Client.prototype.refreshAppCache = function (id, callback) {
var that = this;
this.getApp(id, function (error, app) {
if (error) return callback(error);
var getTaskFunc = app.taskId ? that.getTask.bind(null, app.taskId) : function (next) { return next(); };
getTaskFunc(function (error, task) {
if (error) return callback(error);
if (task) {
app.progress = task.percent;
app.message = task.message;
app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes();
} else {
app.progress = 0;
app.message = '';
app.taskMinutesActive = 0;
}
that._updateAppCache(app);
callback(null, app);
});
});
};
Client.prototype.refreshInstalledApps = function (callback) {
var that = this;
@@ -1814,18 +1812,24 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
if (error) return callback(error);
async.eachLimit(apps, 20, function (app, iteratorCallback) {
var canManageApp = that._userInfo.isAtLeastAdmin;
var getTaskFunc = app.taskId ? that.getTask.bind(null, app.taskId) : function (next) { return next(); };
getTaskFunc(function (error, task) {
if (error) return iteratorCallback(error);
if (task) {
app.progress = task.percent;
app.message = task.message;
app.taskMinutesActive = moment.duration(moment.utc().diff(moment.utc(task.creationTime))).asMinutes();
} else {
app.progress = 0;
app.message = '';
app.taskMinutesActive = 0;
}
if (!canManageApp) {
that._updateAppCache(app);
return iteratorCallback();
}
if (that._installedAppsById[app.id]) {
if (!app.taskId) return iteratorCallback(); // app has active task, get latest
}
that.refreshAppCache(app.id, iteratorCallback);
iteratorCallback(null);
});
}, function iteratorDone(error) {
if (error) return callback(error);