Skip to content

Commit

Permalink
fix: wip debugging mirror logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastCicada committed Mar 7, 2024
1 parent 63b74b6 commit 6c561c5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 125 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt",
"version": "1.7.9",
"version": "1.7.9b1",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ export const addMetadata = async (req, res) => {

export const addMirror = async (req, res) => {
try {
console.info(`ZGB: We are in the organization.controller.js file now`);

await assertIfReadOnlyMode();
await assertWalletIsSynced();
await assertHomeOrgExists();
Expand Down
7 changes: 7 additions & 0 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ const clearPendingRoots = async (storeId) => {
};

const addMirror = async (storeId, url, forceAddMirror = false) => {
logger.info(
`ZGB: in persistance.js, forceAddMirror is ${forceAddMirror}, url is ${url}, storeId is ${storeId}`,
);

await wallet.waitForAllTransactionsToConfirm();
const homeOrg = await Organization.getHomeOrg();
logger.info(
`ZGB: homeorg is ${homeOrg}, forceAddMirror is ${forceAddMirror}, url is ${url}, storeId is ${storeId}`,
);

logger.info(
`Checking mirrors for storeID is ${storeId} with mirror URL ${url}`,
Expand Down
7 changes: 5 additions & 2 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,11 @@ class Organization extends Model {
return registryVersionId;
}

static async addMirror(storeId, url) {
await datalayer.addMirror(storeId, url);
static async addMirror(storeId, url, force = false) {
logger.info(
`ZGB: in organizations.model.js, storeId is ${storeId}, force is ${force}, url is ${url}`,
);
await datalayer.addMirror(storeId, url, force);
}

static async importHomeOrg(orgUid) {
Expand Down
35 changes: 17 additions & 18 deletions src/tasks/mirror-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ const task = new Task('mirror-check', async () => {
await assertDataLayerAvailable();
await assertWalletIsSynced();

logger.info(`ZGB: In the loop to do the mirror-check - no logic run yet`);
// Default AUTO_MIRROR_EXTERNAL_STORES to true if it is null or undefined
const shouldMirror = CONFIG?.AUTO_MIRROR_EXTERNAL_STORES ?? true;

if (!CONFIG.USE_SIMULATOR && shouldMirror) {
logger.info(`ZGB: Conditions met for mirror-check - trying now`);
runMirrorCheck();
}
} catch (error) {
Expand All @@ -43,24 +45,21 @@ const job = new SimpleIntervalJob(
);

const runMirrorCheck = async () => {
const homeOrg = await Organization.getHomeOrg();

if (homeOrg) {
const organizations = await Organization.getOrgsMap();
const orgs = Object.keys(organizations);
for (const org of orgs) {
const orgData = organizations[org];
const mirrorUrl = await getMirrorUrl();

if (mirrorUrl) {
// There is logic within the addMirror function to check if the mirror already exists
await Organization.addMirror(orgData.orgUid, mirrorUrl);
await Organization.addMirror(orgData.registryId, mirrorUrl);
} else {
logger.error(
'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement',
);
}
const organizations = await Organization.getOrgsMap();
const orgs = Object.keys(organizations);
logger.info(`ZGB: orgs available: ${orgs}`);
for (const org of orgs) {
const orgData = organizations[org];
const mirrorUrl = await getMirrorUrl();
logger.info(`ZGB: Working on mirror for ${org} with URL ${mirrorUrl}`);
if (mirrorUrl) {
// There is logic within the addMirror function to check if the mirror already exists
await Organization.addMirror(orgData.orgUid, mirrorUrl, true);
await Organization.addMirror(orgData.registryId, mirrorUrl, true);
} else {
logger.error(
'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement',
);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/datalayer-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const optimizeAndSortKvDiff = (kvDiff) => {
export const getMirrorUrl = async () => {
try {
const { DATALAYER_FILE_SERVER_URL } = getConfig().APP;
logger.debug(`Resolved Mirror Url: ${DATALAYER_FILE_SERVER_URL}`);
logger.info(`Resolved Mirror Url: ${DATALAYER_FILE_SERVER_URL}`);
return DATALAYER_FILE_SERVER_URL;
} catch (error) {
logger.error('Error getting DATALAYER_FILE_SERVER_URL: ${error}');
Expand Down
101 changes: 0 additions & 101 deletions src/utils/ip-tools.js

This file was deleted.

0 comments on commit 6c561c5

Please sign in to comment.