diff --git a/packages/core/server/src/app-supervisor.ts b/packages/core/server/src/app-supervisor.ts index f64bccc63..3006bba00 100644 --- a/packages/core/server/src/app-supervisor.ts +++ b/packages/core/server/src/app-supervisor.ts @@ -32,6 +32,8 @@ export class AppSupervisor extends EventEmitter implements AsyncEmitter { [appName: string]: Application; } = {}; + public lastSeenAt: Map = 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 }) => { diff --git a/packages/core/server/src/gateway/index.ts b/packages/core/server/src/gateway/index.ts index d08177e58..7f65e72de 100644 --- a/packages/core/server/src/gateway/index.ts +++ b/packages/core/server/src/gateway/index.ts @@ -274,6 +274,10 @@ export class Gateway extends EventEmitter { return; } + if (handleApp !== 'main') { + AppSupervisor.getInstance().touchApp(handleApp); + } + app.callback()(req, res); }