From dcb0235d034e742dca4d07f6965b671751ba4185 Mon Sep 17 00:00:00 2001 From: Christina Papadogianni <59121443+ChrisPdgn@users.noreply.github.com> Date: Wed, 22 May 2024 16:06:54 +0300 Subject: [PATCH] fix: pushNotifications health updates (#1039) --- modules/push-notifications/src/PushNotifications.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/push-notifications/src/PushNotifications.ts b/modules/push-notifications/src/PushNotifications.ts index 746729bbb..c8a860d0b 100644 --- a/modules/push-notifications/src/PushNotifications.ts +++ b/modules/push-notifications/src/PushNotifications.ts @@ -47,6 +47,7 @@ export default class PushNotifications extends ManagedModule { }; protected metricsSchema = metricsSchema; private isRunning = false; + private canServe = false; private authServing = false; private adminRouter!: AdminHandlers; private userRouter!: PushNotificationsRoutes; @@ -70,12 +71,15 @@ export default class PushNotifications extends ManagedModule { async onConfig() { if (!ConfigController.getInstance().config.active) { + this.canServe = false; this.updateHealthState(HealthCheckStatus.NOT_SERVING); } else { try { await this.enableModule(); + this.canServe = true; this.updateHealthState(HealthCheckStatus.SERVING); } catch (e) { + this.canServe = false; this.updateHealthState(HealthCheckStatus.NOT_SERVING); } } @@ -200,7 +204,7 @@ export default class PushNotifications extends ManagedModule { } private updateHealthState(stateUpdate?: HealthCheckStatus, authServing?: boolean) { - if (authServing) { + if (authServing !== undefined) { this.authServing = authServing; } const moduleActive = ConfigController.getInstance().config.active; @@ -208,7 +212,10 @@ export default class PushNotifications extends ManagedModule { moduleActive && this.authServing ? HealthCheckStatus.SERVING : HealthCheckStatus.NOT_SERVING; - const requestedState = stateUpdate ?? this.healthState; + const requestedState = + stateUpdate ?? this.canServe + ? HealthCheckStatus.SERVING + : HealthCheckStatus.NOT_SERVING; const nextState = depState === requestedState && requestedState === HealthCheckStatus.SERVING ? HealthCheckStatus.SERVING