Skip to content

Commit

Permalink
fix: mirror logic when no homeorg
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastCicada committed Mar 8, 2024
1 parent 6c561c5 commit 06bfe79
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
9 changes: 1 addition & 8 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,8 @@ 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 Expand Up @@ -572,7 +565,7 @@ const subscribeToStoreOnDataLayer = async (storeId) => {

const mirrorUrl = await getMirrorUrl();

await addMirror(storeId, mirrorUrl);
await addMirror(storeId, mirrorUrl, true);

return data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const createDataLayerStore = async () => {
return storeId;
};

const addMirror = async (storeId, url) => {
return dataLayer.addMirror(storeId, url);
const addMirror = async (storeId, url, force = false) => {
return dataLayer.addMirror(storeId, url, force);
};

const waitForStoreToBeConfirmed = async (storeId, retry = 0) => {
Expand Down
3 changes: 0 additions & 3 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ class Organization extends Model {
}

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);
}

Expand Down
4 changes: 0 additions & 4 deletions src/tasks/mirror-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ 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 @@ -47,11 +45,9 @@ const job = new SimpleIntervalJob(
const runMirrorCheck = async () => {
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);
Expand Down

0 comments on commit 06bfe79

Please sign in to comment.