Skip to content

Commit

Permalink
Merge branch 'develop' into license-blurb-bye-bye
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastCicada authored Feb 7, 2024
2 parents b50ba52 + 2bbcf47 commit 328895f
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 76 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
- runs-on: ubuntu-latest
artifact-name: cadt-linux-x64
build-command: npm run create-linux-x64-dist
sqlite-path: ./node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-x64/
sqlite-path: ./node_modules/sqlite3/build/Release/
- runs-on: macos-latest
artifact-name: cadt-macos-x64
build-command: npm run create-mac-x64-dist
sqlite-path: ./node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-x64/
sqlite-path: ./node_modules/sqlite3/build/Release/
- runs-on: windows-2019
artifact-name: cadt-windows-x64
build-command: npm run create-win-x64-dist
sqlite-path: .\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\
sqlite-path: .\node_modules\sqlite3\build\Release\

steps:
- name: Clean workspace
Expand Down Expand Up @@ -184,8 +184,7 @@ jobs:
- name: Copy sqlite3
run: |
ls ./node_modules/sqlite3/lib/binding/
sudo cp ./node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm64/node_sqlite3.node ./dist/
sudo cp ./node_modules/sqlite3/build/Release/node_sqlite3.node ./dist/
- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down
45 changes: 4 additions & 41 deletions src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,7 @@ const subscribeToStoreOnDataLayer = async (storeId) => {
}
};

const getSubscribedStoreData = async (storeId, retry = 0) => {
if (retry >= 60) {
throw new Error(
`Max retrys exceeded while trying to subscribe to ${storeId}, Can not subscribe to organization`,
);
}

const timeoutInterval = 30000;

const getSubscribedStoreData = async (storeId) => {
const subscriptions = await dataLayer.getSubscriptions(storeId);
const alreadySubscribed = subscriptions.includes(storeId);

Expand All @@ -43,20 +35,7 @@ const getSubscribedStoreData = async (storeId, retry = 0) => {
const response = await subscribeToStoreOnDataLayer(storeId);

if (!response || !response.success) {
if (!response) {
logger.info(
`Response from subscribe RPC came back undefined, is your datalayer running?`,
);
}
logger.info(
`Retrying subscribe to ${storeId}, subscribe failed`,
retry + 1,
);
logger.info('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
);
return getSubscribedStoreData(storeId, retry + 1);
throw new Error(`Failed to subscribe to ${storeId}`);
}
}

Expand All @@ -67,15 +46,7 @@ const getSubscribedStoreData = async (storeId, retry = 0) => {
const storeExistAndIsConfirmed = await dataLayer.getRoot(storeId, true);
logger.info(`Store found in DataLayer: ${storeId}.`);
if (!storeExistAndIsConfirmed) {
logger.info(
`Retrying subscribe to ${storeId}, store not yet confirmed.`,
retry + 1,
);
logger.info('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
);
return getSubscribedStoreData(storeId, retry + 1);
throw new Error(`Store not found in DataLayer: ${storeId}.`);
} else {
logger.debug(`Store is confirmed, proceeding to get data ${storeId}`);
}
Expand All @@ -89,15 +60,7 @@ const getSubscribedStoreData = async (storeId, retry = 0) => {
}

if (_.isEmpty(encodedData?.keys_values)) {
logger.info(
`Retrying subscribe to ${storeId}, No data detected in store.`,
retry + 1,
);
logger.info('...');
await new Promise((resolve) =>
setTimeout(() => resolve(), timeoutInterval),
);
return getSubscribedStoreData(storeId, retry + 1);
throw new Error(`No data found for store ${storeId}`);
}

const decodedData = decodeDataLayerResponse(encodedData);
Expand Down
23 changes: 11 additions & 12 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Organization extends Model {
const orgData = await datalayer.getSubscribedStoreData(orgUid);

if (!orgData.registryId) {
throw new Error(
logger.error(
'Currupted organization, no registryId on the datalayer, can not import',
);
}
Expand Down Expand Up @@ -419,17 +419,16 @@ class Organization extends Model {
);
}

await Promise.all(
defaultOrgs.map(async (org) => {
const exists = await Organization.findOne({
where: { orgUid: org.orgUid },
});

if (!exists) {
Organization.importOrganization(org.orgUid);
}
}),
);
for (let i = 0; i < defaultOrgs.length; i++) {
const org = defaultOrgs[i];
const exists = await Organization.findOne({
where: { orgUid: org.orgUid },
});

if (!exists) {
await Organization.importOrganization(org.orgUid);
}
}
} catch (error) {
logger.info(error);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/project.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';

import chai from 'chai';
const { expect } = chai;
import { expect } from 'chai';

import * as testFixtures from '../test-fixtures';
import { pullPickListValues } from '../../src/utils/data-loaders';
Expand All @@ -27,7 +26,7 @@ describe('Project Resource Integration Tests', function () {
/*
Basic Idea for this test is that we are going to create a project and verify that
the new project propagates through the data layer and into our db. Then we are going
to delete the same project and make sure the delete command propagates through the datalayer
to delete the same project and make sure the delete command propagates through the datalayer
then gets removed from our db.
*/
// create and commit the project to be deleted
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/unit.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';

import chai from 'chai';
import { expect } from 'chai';
import supertest from 'supertest';
const { expect } = chai;

import app from '../../src/server';
import { UnitMirror } from '../../src/models';
Expand Down Expand Up @@ -37,7 +36,7 @@ describe('Unit Resource Integration Tests', function () {
/*
Basic Idea for this test is that we are going to create a unit and verify that
the new unit propagates through the data layer and into our db. Then we are going
to delete the same unit and make sure the delete command propagates through the datalayer
to delete the same unit and make sure the delete command propagates through the datalayer
then gets removed from our db.
*/
// create and commit the unit to be deleted
Expand Down
3 changes: 1 addition & 2 deletions tests/resources/projects.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import chai from 'chai';
import { expect } from 'chai';
import _ from 'lodash';
import * as testFixtures from '../test-fixtures';
import sinon from 'sinon';
import datalayer from '../../src/datalayer';
const { expect } = chai;
import newProject from '../test-data/new-project.js';
import supertest from 'supertest';
import app from '../../src/server';
Expand Down
3 changes: 1 addition & 2 deletions tests/test-fixtures/common-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import chai from 'chai';
const { expect } = chai;
import { expect } from 'chai';

import {
RelatedProject,
Expand Down
3 changes: 1 addition & 2 deletions tests/test-fixtures/project-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';

import supertest from 'supertest';
import chai from 'chai';
const { expect } = chai;
import { expect } from 'chai';

import app from '../../src/server';
import newProject from '../test-data/new-project.js';
Expand Down
3 changes: 1 addition & 2 deletions tests/test-fixtures/staging-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash';

import chai from 'chai';
const { expect } = chai;
import { expect } from 'chai';
import supertest from 'supertest';

import app from '../../src/server';
Expand Down
4 changes: 1 addition & 3 deletions tests/test-fixtures/unit-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import _ from 'lodash';

import supertest from 'supertest';
import chai from 'chai';
const { expect } = chai;

import { expect } from 'chai';
import app from '../../src/server';
import newUnit from '../test-data/new-unit.js';
import updateUnitJson from '../test-data/update-unit.js';
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/request-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const get = (url) => {
}

resolve(res);

});
});
};

0 comments on commit 328895f

Please sign in to comment.