floriday/main.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

import * as vnUtils from './utils.js';
2023-01-11 12:13:22 +00:00
import { models } from './models/index.js';
2023-04-03 19:02:00 +00:00
import moment from 'moment';
2023-01-11 12:13:22 +00:00
2023-04-03 19:02:00 +00:00
console.log = (...args) => console.info(`${new moment().format('HH:mm:ss')} -`, ...args);
async function main() {
let tokenExpirationDate = await vnUtils.getClientToken(models);
const env = process.env;
env.SYNC_SEQUENCE ? await vnUtils.syncSequence() : null;
env.SYNC_SUPPLIER ? await vnUtils.syncSuppliers() : null;
await vnUtils.syncConnections();
env.SYNC_TRADEITEM ? await vnUtils.syncTradeItems() : null;
console.log('Synced trade items');
try {
while (true) {
try{
console.log('Querying the API to check for new data...');
console.log('Current token expiration date: ', tokenExpirationDate);
if (moment().isAfter(tokenExpirationDate)) {
console.log('Token expired, getting a new one...');
tokenExpirationDate = await vnUtils.getClientToken(models);
}
await vnUtils.syncSupplyLines();
} catch (error) {
console.error(error);
}
if (env.STATUS == 'development') {
await vnUtils.sleep(120000);
} else {
await vnUtils.sleep(300000);
2023-01-24 12:51:44 +00:00
}
2023-01-16 13:52:08 +00:00
}
2023-04-03 19:02:00 +00:00
} catch (error) {
console.error('Unable to connect to the database:', error);
2023-01-16 13:52:08 +00:00
}
2023-04-03 19:02:00 +00:00
}
2023-04-03 19:02:00 +00:00
main()