Skip to content

Commit

Permalink
fix: pushNotifications health updates (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPdgn committed May 22, 2024
1 parent 396984b commit dcb0235
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/push-notifications/src/PushNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class PushNotifications extends ManagedModule<Config> {
};
protected metricsSchema = metricsSchema;
private isRunning = false;
private canServe = false;
private authServing = false;
private adminRouter!: AdminHandlers;
private userRouter!: PushNotificationsRoutes;
Expand All @@ -70,12 +71,15 @@ export default class PushNotifications extends ManagedModule<Config> {

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);
}
}
Expand Down Expand Up @@ -200,15 +204,18 @@ export default class PushNotifications extends ManagedModule<Config> {
}

private updateHealthState(stateUpdate?: HealthCheckStatus, authServing?: boolean) {
if (authServing) {
if (authServing !== undefined) {
this.authServing = authServing;
}
const moduleActive = ConfigController.getInstance().config.active;
const depState =
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
Expand Down

0 comments on commit dcb0235

Please sign in to comment.