Skip to content

Commit

Permalink
test: all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D authored and cmmarslender committed Oct 12, 2023
1 parent 6386a34 commit 5f7ad86
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 141 deletions.
42 changes: 23 additions & 19 deletions src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,29 @@ const logDebounce = _.debounce(() => {
}, 120000);

export const safeMirrorDbHandler = (callback) => {
try {
sequelizeMirror
.authenticate()
.then(async () => {
try {
await callback();
} catch (e) {
logger.error(`mirror_error:${e.message}`);
}
})
.catch(() => {
logDebounce();
});
} catch (error) {
logger.error(
'MirrorDB tried to update before it was initialize, will try again later',
error,
);
}
return new Promise((resolve) => {
try {
sequelizeMirror
.authenticate()
.then(async () => {
try {
await callback();
} catch (e) {
logger.error(`mirror_error:${e.message}`);
}
})
.catch(() => {
logDebounce();
});
} catch (error) {
logger.error(
'MirrorDB tried to update before it was initialize, will try again later',
error,
);
} finally {
resolve();
}
});
};

export const sanitizeSqliteFtsQuery = (query) => {
Expand Down
19 changes: 18 additions & 1 deletion src/datalayer/syncService.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';

import { decodeHex, decodeDataLayerResponse } from '../utils/datalayer-utils';
import { Organization, Staging, ModelKeys } from '../models';
import { Organization, Staging, ModelKeys, Simulator } from '../models';
import { getConfig } from '../utils/config-loader';
import { logger } from '../config/logger.cjs';

Expand Down Expand Up @@ -278,11 +278,28 @@ const getSubscribedStoreData = async (storeId, retry = 0) => {
const getRootHistory = (storeId) => {
if (!USE_SIMULATOR) {
return dataLayer.getRootHistory(storeId);
} else {
return [
{
confirmed: true,
root_hash:
'0xs571e7fcf464b3dc1d31a71894633eb47cb9dbdb824f6b4a535ed74f23f32e50',
timestamp: 1678518050,
},
{
confirmed: true,
root_hash:
'0xf571e7fcf464b3dc1d31a71894633eb47cb9dbdb824f6b4a535ed74f23f32e50',
timestamp: 1678518053,
},
];
}
};

const getRootDiff = (storeId, root1, root2) => {
if (!USE_SIMULATOR) {
return Simulator.getMockedKvDiffFromStagingTable();
} else {
return dataLayer.getRootDiff(storeId, root1, root2);
}
};
Expand Down
28 changes: 23 additions & 5 deletions src/models/audit/audit.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,35 @@ import findDuplicateIssuancesSql from './sql/find-duplicate-issuances.sql.js';

class Audit extends Model {
static async create(values, options) {
safeMirrorDbHandler(() => AuditMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await AuditMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => AuditMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await AuditMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => AuditMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await AuditMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}

Expand Down
28 changes: 23 additions & 5 deletions src/models/co-benefits/co-benefits.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,36 @@ class CoBenefit extends Model {
}

static async create(values, options) {
safeMirrorDbHandler(() => CoBenefitMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await CoBenefitMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => CoBenefitMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await CoBenefitMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => CoBenefitMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await CoBenefitMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}
}

Expand Down
29 changes: 24 additions & 5 deletions src/models/estimations/estimations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,37 @@ class Estimation extends Model {
}

static async create(values, options) {
safeMirrorDbHandler(() => EstimationMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};

await EstimationMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => EstimationMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await EstimationMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => EstimationMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await EstimationMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}
}

Expand Down
28 changes: 23 additions & 5 deletions src/models/issuances/issuances.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,35 @@ class Issuance extends Model {
}

static async create(values, options) {
safeMirrorDbHandler(() => IssuanceMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await IssuanceMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => IssuanceMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await IssuanceMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => IssuanceMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await IssuanceMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}
}
Expand Down
28 changes: 23 additions & 5 deletions src/models/labelUnits/labelUnits.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,35 @@ import { LabelUnitMirror } from './labelUnits.model.mirror';

class LabelUnit extends Model {
static async create(values, options) {
safeMirrorDbHandler(() => LabelUnitMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelUnitMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => LabelUnitMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelUnitMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => LabelUnitMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelUnitMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}
}
Expand Down
28 changes: 23 additions & 5 deletions src/models/labels/labels.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,35 @@ class Label extends Model {
}

static async create(values, options) {
safeMirrorDbHandler(() => LabelMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => LabelMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => LabelMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await LabelMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}
}
Expand Down
28 changes: 23 additions & 5 deletions src/models/locations/locations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,35 @@ class ProjectLocation extends Model {
}

static async create(values, options) {
safeMirrorDbHandler(() => ProjectLocationMirror.create(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await ProjectLocationMirror.create(values, mirrorOptions);
});
return super.create(values, options);
}

static async destroy(values, options) {
safeMirrorDbHandler(() => ProjectLocationMirror.destroy(values, options));
return super.destroy(values, options);
static async destroy(options) {
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await ProjectLocationMirror.destroy(mirrorOptions);
});
return super.destroy(options);
}

static async upsert(values, options) {
safeMirrorDbHandler(() => ProjectLocationMirror.upsert(values, options));
safeMirrorDbHandler(async () => {
const mirrorOptions = {
...options,
transaction: options?.mirrorTransaction,
};
await ProjectLocationMirror.upsert(values, mirrorOptions);
});
return super.upsert(values, options);
}
}
Expand Down
Loading

0 comments on commit 5f7ad86

Please sign in to comment.