@kumori/aurora-backend-handler 1.0.136 → 1.0.137
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/helpers/service-helper.ts +54 -2
- package/package.json +2 -2
- package/websocket-manager.ts +2 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Channel, Resource, Service, Tenant, Usage } from "@kumori/aurora-interfaces";
|
|
1
|
+
import { Channel, errors, Notification, Resource, Service, Tenant, Usage } from "@kumori/aurora-interfaces";
|
|
2
2
|
import { Revision } from "@kumori/aurora-interfaces/interfaces/revision-interface";
|
|
3
3
|
import { getTimestamp } from "../utils/utils";
|
|
4
4
|
|
|
@@ -530,4 +530,56 @@ export const mapChannelsFromApiData = (
|
|
|
530
530
|
mapChannels(apiData.duplex, duplexChannels);
|
|
531
531
|
|
|
532
532
|
return { serverChannels, clientChannels, duplexChannels };
|
|
533
|
-
};
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const instancesNotRunningNotifications = new Map<string, Notification>();
|
|
536
|
+
let lastInstancesNotRunningNotificationDate = 0;
|
|
537
|
+
|
|
538
|
+
const hasInstancesNotRunning = (service: Service): boolean =>
|
|
539
|
+
(service.role ?? []).some((role) =>
|
|
540
|
+
(role.instances ?? []).some(
|
|
541
|
+
(instance) => instance.status?.toLowerCase() !== "running",
|
|
542
|
+
),
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
export const syncInstancesNotRunningNotifications = (
|
|
546
|
+
services: Iterable<Service>,
|
|
547
|
+
eventHelper: any,
|
|
548
|
+
): void => {
|
|
549
|
+
const pending = new Map<string, Record<string, string>>();
|
|
550
|
+
for (const service of services) {
|
|
551
|
+
if (service.status?.code === "REMOVING_SERVICE") continue;
|
|
552
|
+
if (!hasInstancesNotRunning(service)) continue;
|
|
553
|
+
const { tenant, account, environment, name } = service;
|
|
554
|
+
pending.set(`${tenant}/${account}/${environment}/${name}`, {
|
|
555
|
+
tenant,
|
|
556
|
+
account,
|
|
557
|
+
environment,
|
|
558
|
+
service: name,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
instancesNotRunningNotifications.forEach((notification, key) => {
|
|
563
|
+
if (pending.has(key)) return;
|
|
564
|
+
instancesNotRunningNotifications.delete(key);
|
|
565
|
+
eventHelper.notification.publish.deletion(notification);
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
pending.forEach((data, key) => {
|
|
569
|
+
if (instancesNotRunningNotifications.has(key)) return;
|
|
570
|
+
lastInstancesNotRunningNotificationDate = Math.max(
|
|
571
|
+
Date.now(),
|
|
572
|
+
lastInstancesNotRunningNotificationDate + 1,
|
|
573
|
+
);
|
|
574
|
+
const notification: Notification = {
|
|
575
|
+
type: "warning",
|
|
576
|
+
subtype: errors.service.instancesNotRunning.subtype,
|
|
577
|
+
date: lastInstancesNotRunningNotificationDate.toString(),
|
|
578
|
+
status: "unread",
|
|
579
|
+
notificationType: "regular",
|
|
580
|
+
data,
|
|
581
|
+
};
|
|
582
|
+
instancesNotRunningNotifications.set(key, notification);
|
|
583
|
+
eventHelper.notification.publish.creation(notification);
|
|
584
|
+
});
|
|
585
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumori/aurora-backend-handler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.137",
|
|
4
4
|
"description": "backend handler",
|
|
5
5
|
"main": "backend-handler.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"glob": "^11.0.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@kumori/aurora-interfaces": "
|
|
14
|
+
"@kumori/aurora-interfaces": "1.0.41",
|
|
15
15
|
"@kumori/kumori-dsl-generator": "1.0.11",
|
|
16
16
|
"@kumori/kumori-module-generator": "^1.1.6",
|
|
17
17
|
"ts-node": "^10.9.2",
|
package/websocket-manager.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
handleServiceOperationError,
|
|
50
50
|
handleServiceOperationSuccess,
|
|
51
51
|
mapChannelsFromApiData,
|
|
52
|
+
syncInstancesNotRunningNotifications,
|
|
52
53
|
} from "./helpers/service-helper";
|
|
53
54
|
import {
|
|
54
55
|
handleAccountEvent,
|
|
@@ -685,6 +686,7 @@ const rebuildHierarchy = () => {
|
|
|
685
686
|
accountsMap.values(),
|
|
686
687
|
eventHelper,
|
|
687
688
|
);
|
|
689
|
+
syncInstancesNotRunningNotifications(servicesMap.values(), eventHelper);
|
|
688
690
|
|
|
689
691
|
tenantsMap.forEach((tenant) => {
|
|
690
692
|
tenant.accounts = Array.from(accountsMap.values()).filter((account) => {
|