Skip to content

Commit 8042c40

Browse files
PavelPashovnkaradzhov
authored andcommitted
refactor: improve enterprise manager push notification handling
1 parent decb2cf commit 8042c40

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

packages/client/lib/client/enterprise-maintenance-manager.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,39 @@ export default class EnterpriseMaintenanceManager {
120120

121121
#onPush = (push: Array<any>): boolean => {
122122
dbgMaintenance("ONPUSH:", push.map(String));
123-
switch (push[0].toString()) {
123+
124+
if (!Array.isArray(push) || !["MOVING", "MIGRATING", "MIGRATED", "FAILING_OVER", "FAILED_OVER"].includes(String(push[0]))) {
125+
return false;
126+
}
127+
128+
const type = String(push[0]);
129+
130+
emitDiagnostics({
131+
type,
132+
timestamp: Date.now(),
133+
data: {
134+
push: push.map(String),
135+
},
136+
});
137+
switch (type) {
124138
case PN.MOVING: {
125139
// [ 'MOVING', '17', '15', '54.78.247.156:12075' ]
126140
// ^seq ^after ^new ip
127141
const afterSeconds = push[2];
128142
const url: string | null = push[3] ? String(push[3]) : null;
129143
dbgMaintenance("Received MOVING:", afterSeconds, url);
130-
emitDiagnostics({
131-
type: PN.MOVING,
132-
timestamp: Date.now(),
133-
data: {
134-
afterSeconds,
135-
url,
136-
},
137-
});
138144
this.#onMoving(afterSeconds, url);
139145
return true;
140146
}
141147
case PN.MIGRATING:
142148
case PN.FAILING_OVER: {
143149
dbgMaintenance("Received MIGRATING|FAILING_OVER");
144-
emitDiagnostics({
145-
type: PN.MIGRATING,
146-
timestamp: Date.now(),
147-
});
148150
this.#onMigrating();
149151
return true;
150152
}
151153
case PN.MIGRATED:
152154
case PN.FAILED_OVER: {
153155
dbgMaintenance("Received MIGRATED|FAILED_OVER");
154-
emitDiagnostics({
155-
type: PN.MIGRATED,
156-
timestamp: Date.now(),
157-
});
158156
this.#onMigrated();
159157
return true;
160158
}

0 commit comments

Comments
 (0)