Skip to content

Commit

Permalink
fix(grpc-sdk): module inconsistency on momentary core unavailability (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Jul 22, 2022
1 parent ae78612 commit d8c753c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 366 deletions.
6 changes: 3 additions & 3 deletions libraries/grpc-sdk/src/modules/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ export class Config extends ConduitModule<typeof ConfigDefinition> {
async watchModules() {
const self = this;
this.emitter.setMaxListeners(150);
self.emitter.emit('serving-modules-update', await self.moduleList().catch());
try {
const call = this.client!.watchModules({});
for await (const data of call) {
self.emitter.emit('serving-modules-update', data.modules);
}
} catch (error) {
// uncomment for debug when needed
// currently is misleading if left on
// ConduitGrpcSdk.Logger.warn('Connection to gRPC server closed');
self.coreLive = false;
ConduitGrpcSdk.Logger.warn('Core unhealthy');
}
}
}
31 changes: 12 additions & 19 deletions packages/core/src/config-manager/service-discovery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,19 @@ export class ServiceDiscovery {
}

moduleList(call: GrpcRequest<null>, callback: GrpcCallback<ModuleListResponse>) {
if (this.registeredModules.size !== 0) {
const modules: {
moduleName: string;
url: string;
serving: boolean;
}[] = [];
this.registeredModules.forEach((value: RegisteredModule, key: string) => {
modules.push({
moduleName: key,
url: value.address,
serving: value.serving,
});
const modules: {
moduleName: string;
url: string;
serving: boolean;
}[] = [];
this.registeredModules.forEach((value: RegisteredModule, key: string) => {
modules.push({
moduleName: key,
url: value.address,
serving: value.serving,
});
callback(null, { modules });
} else {
callback({
code: status.NOT_FOUND,
message: 'Modules not available',
});
}
});
callback(null, { modules });
}

watchModules(call: ServerWritableStream<void, ModuleListResponse>) {
Expand Down
Loading

0 comments on commit d8c753c

Please sign in to comment.