Skip to content

Commit

Permalink
fix(functions,sms): admin route registration before module registrati…
Browse files Browse the repository at this point in the history
…on errors (#625)
  • Loading branch information
kon14 authored May 18, 2023
1 parent 4d8c48d commit a456511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
35 changes: 20 additions & 15 deletions modules/functions/src/Functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,32 @@ export default class Functions extends ManagedModule<Config> {
await this.grpcSdk.waitForExistence('database');
this.database = this.grpcSdk.database!;
await this.registerSchemas();
this.grpcSdk
.waitForExistence('router')
.then(() => {
this.isRunning = true;
this.functionsController = new FunctionController(this.grpcServer, this.grpcSdk);
this.adminRouter = new AdminHandlers(
this.grpcServer,
this.grpcSdk,
this.functionsController,
);
return this.functionsController.refreshRoutes();
})
.catch(e => {
ConduitGrpcSdk.Logger.error(e.message);
});
}

async onConfig() {
if (!ConfigController.getInstance().config.active) {
this.updateHealth(HealthCheckStatus.NOT_SERVING);
}
if (!this.isRunning) {
this.grpcSdk
.waitForExistence('router')
.then(() => {
this.isRunning = true;
this.functionsController = new FunctionController(
this.grpcServer,
this.grpcSdk,
);
this.adminRouter = new AdminHandlers(
this.grpcServer,
this.grpcSdk,
this.functionsController,
);
return this.functionsController.refreshRoutes();
})
.catch(e => {
ConduitGrpcSdk.Logger.error(e.message);
});
}
this.updateHealth(HealthCheckStatus.SERVING);
}

Expand Down
5 changes: 1 addition & 4 deletions modules/sms/src/Sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ export default class Sms extends ManagedModule<Config> {
this.updateHealth(HealthCheckStatus.UNKNOWN, true);
}

async onServerStart() {
this.adminRouter = new AdminHandlers(this.grpcServer, this.grpcSdk, this._provider);
}

async preConfig(config: any) {
if (
isNil(config.active) ||
Expand All @@ -61,6 +57,7 @@ export default class Sms extends ManagedModule<Config> {
if (!ConfigController.getInstance().config.active) {
this.updateHealth(HealthCheckStatus.NOT_SERVING);
} else {
this.adminRouter = new AdminHandlers(this.grpcServer, this.grpcSdk, this._provider);
await this.initProvider();
}
}
Expand Down

0 comments on commit a456511

Please sign in to comment.