Skip to content

Commit

Permalink
feat: add better log messages when subscribing to store
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed May 9, 2022
1 parent 7f9fc14 commit d37e0f9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,20 @@ const getSubscribedStoreData = async (
retry = 0,
) => {
if (retry >= 60) {
throw new Error('Max retrys exceeded, Can not subscribe to organization');
throw new Error(
`Max retrys exceeded while trying to subscribe to ${storeId}, Can not subscribe to organization`,
);
}

const timeoutInterval = 30000;

if (!alreadySubscribed) {
const response = await subscribeToStoreOnDataLayer(storeId, ip, port);
if (!response.success) {
logger.debug(`Retrying...`, retry + 1);
if (!response || response.success) {
logger.debug(
`Retrying subscribe to ${storeId}, subscribe failed`,
retry + 1,
);
logger.debug('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
Expand All @@ -203,7 +208,10 @@ const getSubscribedStoreData = async (
if (!USE_SIMULATOR) {
const storeExistAndIsConfirmed = await dataLayer.getRoot(storeId, true);
if (!storeExistAndIsConfirmed) {
logger.debug(`Retrying...`, retry + 1);
logger.debug(
`Retrying subscribe to ${storeId}, store not yet confirmed.`,
retry + 1,
);
logger.debug('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
Expand All @@ -222,7 +230,10 @@ const getSubscribedStoreData = async (
logger.debug(encodedData?.keys_values);

if (_.isEmpty(encodedData?.keys_values)) {
logger.debug(`Retrying...`, retry + 1);
logger.debug(
`Retrying subscribe to ${storeId}, No data detected in store.`,
retry + 1,
);
logger.debug('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
Expand Down

0 comments on commit d37e0f9

Please sign in to comment.