Skip to content

Commit

Permalink
fix: delay start of scheduler to give models time to initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Mar 13, 2022
1 parent a44036e commit 05278ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
26 changes: 16 additions & 10 deletions src/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ const mirrorConfig =
export const sequelizeMirror = new Sequelize(config[mirrorConfig]);

export const safeMirrorDbHandler = (callback) => {
sequelizeMirror
.authenticate()
.then(() => {
callback();
})
.catch(() => {
if (process.env.DB_HOST && process.env.DB_HOST !== '') {
log('Mirror DB not connected');
}
});
try {
sequelizeMirror
.authenticate()
.then(() => {
callback();
})
.catch(() => {
if (process.env.DB_HOST && process.env.DB_HOST !== '') {
log('Mirror DB not connected');
}
});
} catch (error) {
console.log(
'MirrorDB tried to update before it was initialize, will try again later',
);
}
};

export const sanitizeSqliteFtsQuery = (query) => {
Expand Down
4 changes: 3 additions & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ app.use('/v1', V1Router);
sequelize.authenticate().then(async () => {
console.log('Connected to database');
await prepareDb();
scheduler.start();
setTimeout(() => {
scheduler.start();
}, 5000);
});

app.use((err, req, res, next) => {
Expand Down
9 changes: 5 additions & 4 deletions src/utils/data-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ export const assertSumOfSplitUnitsIsValid = (
serialNumberPattern,
splitRecords,
) => {
const sumOfSplitUnits = splitRecords.reduce(
(previousValue, currentValue) =>
previousValue.unitCount + currentValue.unitCount,
);
const sumOfSplitUnits =
splitRecords.reduce(
(previousValue, currentValue) =>
previousValue.unitCount + currentValue.unitCount,
) + 1; // Add one to handle inclusiveness boundry

const [unitBlockStart, unitBlockEnd, unitCount] = transformSerialNumberBlock(
serialNumberBlock,
Expand Down

0 comments on commit 05278ac

Please sign in to comment.