fix: handle upgrade properly in signal router
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -25,6 +25,8 @@ export class DevToolsBackendApi {
|
||||
listExternalDependencyDetails(): Promise<ExternalDependency[]>;
|
||||
// (undocumented)
|
||||
listInfo(): Promise<DevToolsInfo>;
|
||||
// (undocumented)
|
||||
listResourceUtilization(): Promise<string>;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
||||
@@ -203,17 +203,21 @@ export class DevToolsBackendApi {
|
||||
return configInfo;
|
||||
}
|
||||
|
||||
public async listInfo(): Promise<DevToolsInfo> {
|
||||
const operatingSystem = `${os.hostname()}: ${os.type} ${os.release} - ${
|
||||
os.platform
|
||||
}/${os.arch}`;
|
||||
public async listResourceUtilization(): Promise<string> {
|
||||
const usedMem = Math.floor((os.totalmem() - os.freemem()) / (1024 * 1024));
|
||||
const resources = `Memory: ${usedMem}/${Math.floor(
|
||||
return `Memory: ${usedMem}/${Math.floor(
|
||||
os.totalmem() / (1024 * 1024),
|
||||
)}MB - Load: ${os
|
||||
.loadavg()
|
||||
.map(v => v.toFixed(2))
|
||||
.join('/')}`;
|
||||
}
|
||||
|
||||
public async listInfo(): Promise<DevToolsInfo> {
|
||||
const operatingSystem = `${os.hostname()}: ${os.type} ${os.release} - ${
|
||||
os.platform
|
||||
}/${os.arch}`;
|
||||
|
||||
const nodeJsVersion = process.version;
|
||||
|
||||
/* eslint-disable-next-line no-restricted-syntax */
|
||||
@@ -247,7 +251,7 @@ export class DevToolsBackendApi {
|
||||
|
||||
const info: DevToolsInfo = {
|
||||
operatingSystem: operatingSystem ?? 'N/A',
|
||||
resourceUtilization: resources ?? 'N/A',
|
||||
resourceUtilization: (await this.listResourceUtilization()) ?? 'N/A',
|
||||
nodeJsVersion: nodeJsVersion ?? 'N/A',
|
||||
backstageVersion:
|
||||
backstageJson && backstageJson.version ? backstageJson.version : 'N/A',
|
||||
|
||||
@@ -56,9 +56,11 @@ export async function createRouter(
|
||||
if (signalService) {
|
||||
// Publish info periodically using the signal service
|
||||
setInterval(async () => {
|
||||
if (signalService.hasSubscribers('devtools:info')) {
|
||||
const info = await devToolsBackendApi.listInfo();
|
||||
await signalService.publish('*', 'devtools:info', info);
|
||||
if (signalService.hasSubscribers('devtools:resources')) {
|
||||
const info = await devToolsBackendApi.listResourceUtilization();
|
||||
await signalService.publish('*', 'devtools:resources', {
|
||||
resources: info,
|
||||
});
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user