feat: record last seen at in supervisor (#4345)

This commit is contained in:
ChengLei Shao 2024-05-14 17:05:21 +08:00 committed by GitHub
parent 91c24efd0b
commit 33e14cbc2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -32,6 +32,8 @@ export class AppSupervisor extends EventEmitter implements AsyncEmitter {
[appName: string]: Application;
} = {};
public lastSeenAt: Map<string, number> = new Map();
public appErrors: {
[appName: string]: Error;
} = {};
@ -180,6 +182,14 @@ export class AppSupervisor extends EventEmitter implements AsyncEmitter {
return !!this.apps[appName];
}
touchApp(appName: string) {
if (!this.hasApp(appName)) {
return;
}
this.lastSeenAt.set(appName, Math.floor(Date.now() / 1000));
}
// add app into supervisor
addApp(app: Application) {
// if there is already an app with the same name, throw error
@ -245,6 +255,7 @@ export class AppSupervisor extends EventEmitter implements AsyncEmitter {
delete this.appErrors[app.name];
delete this.lastMaintainingMessage[app.name];
delete this.statusBeforeCommanding[app.name];
this.lastSeenAt.delete(app.name);
});
app.on('maintainingMessageChanged', ({ message, maintainingStatus }) => {

View File

@ -274,6 +274,10 @@ export class Gateway extends EventEmitter {
return;
}
if (handleApp !== 'main') {
AppSupervisor.getInstance().touchApp(handleApp);
}
app.callback()(req, res);
}