Skip to content

Commit

Permalink
fix(facade): Add retry mechanism for set apiKey command incase consum…
Browse files Browse the repository at this point in the history
…er is not yet initialized
  • Loading branch information
Arun-KumarH committed Mar 22, 2024
1 parent e67ee31 commit bdb5162
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/facade/src/modules/identity/api-key/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type Application from 'koa';
import { Events, registerProtoMeta } from '@restorecommerce/kafka-client';
import { createServiceConfig } from '@restorecommerce/service-config';
import { protoMetadata as commandInterfaceMeta } from '@restorecommerce/rc-grpc-clients/dist/generated-server/io/restorecommerce/commandinterface.js';
import * as retry from 'retry';

// const Router = require('koa-router');

Expand Down Expand Up @@ -93,11 +94,17 @@ const initApiKey = (logger: Logger, apiKey: boolean | string) => {
} else {
bootstrapApiKey = apiKey as string;
}
exectueSetAPIKeyCommand(bootstrapApiKey, logger).then((resp) => {
logger.info('SetApiKey command response', resp);
logger.info(`Bootstrap API Key is: ${bootstrapApiKey}`);
}).catch(err => {
logger.error('Error executing setApiKey command', err);
const operation = retry.operation();
operation.attempt(async () => {
exectueSetAPIKeyCommand(bootstrapApiKey, logger).then((resp) => {
logger.info('SetApiKey command response', resp);
logger.info(`Bootstrap API Key is: ${bootstrapApiKey}`);
}).catch(err => {
logger.error('Error executing setApiKey command', err);
operation.retry(err);
const attemptNo = (operation.attempts as () => number)();
logger.info(`Retry exectueSetAPIKeyCommand, attempt no: ${attemptNo}`);
});
});
};

Expand Down

0 comments on commit bdb5162

Please sign in to comment.