Skip to content

Commit

Permalink
feat: mirror check task automatically adds missing governance mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Oct 29, 2024
1 parent 78c4b95 commit 80986ab
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/models/governance/governance.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Governance extends Model {
const governanceVersionId = await datalayer.createDataLayerStore();

const revertOrganizationIfFailed = async () => {
logger.info('Reverting Failed Governance Body Creation');
logger.warn('Reverting Failed Governance Body Creation');
await Meta.destroy({ where: { metaKey: 'governanceBodyId' } });
};

Expand All @@ -44,7 +44,6 @@ class Governance extends Model {
);

const onConfirm = async () => {
logger.info('Organization confirmed, you are ready to go');
await Meta.upsert({
metaKey: 'governanceBodyId',
metaValue: governanceVersionId,
Expand All @@ -53,6 +52,7 @@ class Governance extends Model {
metaKey: 'mainGoveranceBodyId',
metaValue: governanceBodyId,
});
logger.info('Governance body confirmed, you are ready to go');
};

if (!USE_SIMULATOR) {
Expand Down
53 changes: 41 additions & 12 deletions src/tasks/mirror-check.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SimpleIntervalJob, Task } from 'toad-scheduler';
import { Organization } from '../models';
import { Meta, Organization } from '../models';
import {
assertDataLayerAvailable,
assertWalletIsSynced,
Expand All @@ -23,7 +23,7 @@ const task = new Task('mirror-check', async () => {
const shouldMirror = CONFIG?.AUTO_MIRROR_EXTERNAL_STORES ?? true;

if (!CONFIG.USE_SIMULATOR && shouldMirror) {
runMirrorCheck();
await runMirrorCheck();
}
} catch (error) {
logger.error(
Expand All @@ -43,20 +43,49 @@ const job = new SimpleIntervalJob(
);

const runMirrorCheck = async () => {
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) {
const mirrorUrl = await getMirrorUrl();

if (mirrorUrl) {
const governanceOrgUidResult = await Meta.findOne({
where: { metaKey: 'governanceBodyId' },
attributes: ['metaValue'],
raw: true,
});
const governanceRegistryIdResult = await Meta.findOne({
where: { metaKey: 'mainGoveranceBodyId' },
attributes: ['metaValue'],
raw: true,
});

if (
governanceOrgUidResult?.metaValue &&
governanceRegistryIdResult?.metaValue
) {
// There is logic within the addMirror function to check if the mirror already exists
await Organization.addMirror(
governanceOrgUidResult?.metaValue,
mirrorUrl,
true,
);
await Organization.addMirror(
governanceRegistryIdResult?.metaValue,
mirrorUrl,
true,
);
}

const organizations = await Organization.getOrgsMap();
const orgs = Object.keys(organizations);
for (const org of orgs) {
const orgData = organizations[org];
// 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.info(
'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcement',
);
}
} else {
logger.info(
'DATALAYER_FILE_SERVER_URL not set, skipping mirror announcements',
);
}
};

Expand Down

0 comments on commit 80986ab

Please sign in to comment.