import * as vnUtils from './utils.js'; import { models } from './models/index.js'; import moment from 'moment'; 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); } } } catch (error) { console.error('Unable to connect to the database:', error); } } main()