47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import moment from 'moment';
|
|
import * as vnUtils from './utils.js';
|
|
//import cliProgress from 'cli-progress';
|
|
|
|
import dotenv from 'dotenv';
|
|
dotenv.config();
|
|
|
|
import { models } from './models/index.js';
|
|
|
|
console.log = function () {
|
|
let args = Array.prototype.slice.call(arguments);
|
|
args.unshift(new moment().format('HH:mm:ss') + ' -');
|
|
console.info.apply(console, args);
|
|
};
|
|
|
|
let tokenExpirationDate = await vnUtils.getClientToken(models);
|
|
|
|
process.env.SYNC_SEQUENCE ? await vnUtils.syncSequence() : null;
|
|
process.env.SYNC_SUPPLIER ? await vnUtils.syncSuppliers() : null;
|
|
//process.env.SYNC_TRADEITEM ? await vnUtils.syncTradeItems() : null;
|
|
|
|
try {
|
|
// eslint-disable-next-line no-constant-condition
|
|
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);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
if (process.env.STATUS == 'development') {
|
|
await vnUtils.sleep(15000);
|
|
} else {
|
|
await vnUtils.sleep(30000);
|
|
}
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Unable to connect to the database:', error);
|
|
} |