Skip to content

Commit

Permalink
Merge pull request #174 from Chia-Network/dev/loggin
Browse files Browse the repository at this point in the history
feat: logging for zach
  • Loading branch information
MichaelTaylor3D authored Oct 17, 2023
2 parents 864adf3 + b52b906 commit 7e1a79d
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions src/api/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ const getOrgMetaData = async (orgUid) => {
const waitForRegistryDataSync = async (options = {}) => {
await mutex.waitForUnlock();

let isFirstSyncAfterFailure = false;

if (!mutex.isLocked()) {
const releaseMutex = await mutex.acquire();
try {
Expand All @@ -562,44 +564,72 @@ const waitForRegistryDataSync = async (options = {}) => {
const homeOrg = await getHomeOrg();

if (!homeOrg) {
logger.warn("Cannot find the home org from the Registry. Please verify your Registry is running and you have created a Home Organization.");
logger.warn(
"Cannot find the home org from the Registry. Please verify your Registry is running and you have created a Home Organization."
);
isFirstSyncAfterFailure = true;
continue;
}

const onChainRegistryRoot = await datalayer.getRoot({ id: homeOrg.registryId });
const onChainRegistryRoot = await datalayer.getRoot({
id: homeOrg.registryId,
});

if (!onChainRegistryRoot.confirmed) {
console.log("Waiting for Registry root to confirm");
logger.debug("Waiting for Registry root to confirm");
isFirstSyncAfterFailure = true;
continue;
}

if (onChainRegistryRoot.hash === constants.emptySingletonHash && opts.throwOnEmptyRegistry) {
throw new Error("Registry is empty. Please add some data to run auto retirement task.");
if (
onChainRegistryRoot.hash === constants.emptySingletonHash &&
opts.throwOnEmptyRegistry
) {
throw new Error(
"Registry is empty. Please add some data to run auto retirement task."
);
}

if (onChainRegistryRoot.hash !== homeOrg.registryHash) {
console.log("Waiting for Registry to sync with latest registry root.", {
onChainRoot: onChainRegistryRoot.hash,
homeOrgRegistryRoot: homeOrg.registryHash,
});
logger.debug(
`Waiting for Registry to sync with latest registry root.
${JSON.stringify({
onChainRoot: onChainRegistryRoot.hash,
homeOrgRegistryRoot: homeOrg.registryHash,
}, null, 2)}`
);
isFirstSyncAfterFailure = true;
continue;
}

const onChainOrgRoot = await datalayer.getRoot({ id: homeOrg.orgUid });

if (!onChainOrgRoot.confirmed) {
console.log("Waiting for Organization root to confirm");
logger.debug("Waiting for Organization root to confirm");
continue;
}

if (onChainOrgRoot.hash !== homeOrg.orgHash) {
console.log("Waiting for Registry to sync with latest organization root.", {
onChainRoot: onChainOrgRoot.hash,
homeOrgRoot: homeOrg.orgHash,
});
logger.debug(
`Waiting for Registry to sync with latest organization root. ,
${JSON.stringify(
{
onChainRoot: onChainOrgRoot.hash,
homeOrgRoot: homeOrg.orgHash,
},
null,
2
)}`
);
isFirstSyncAfterFailure = true;
continue;
}

// Log the message if conditions are met for the first time after failure
if (isFirstSyncAfterFailure) {
logger.info("CADT is SYNCED! Proceeding with the task.");
}

// Exit the loop if all conditions are met
break;
}
Expand Down

0 comments on commit 7e1a79d

Please sign in to comment.