34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
import * as vnUtils from './utils.js';
|
|
import { models } from './models/index.js';
|
|
import moment from 'moment';
|
|
|
|
// Añade la hora a todos los console.log
|
|
// console.log = (...args) => console.info(`${new moment().format('HH:mm:ss')} -`, ...args);
|
|
const env = process.env;
|
|
class Floriday {
|
|
async start() {
|
|
try {
|
|
this.tokenExpirationDate = await vnUtils.getClientToken(models);
|
|
if (JSON.parse(env.SYNC_SEQUENCE)) await vnUtils.syncSequence()
|
|
if (JSON.parse(env.SYNC_SUPPLIER)) await vnUtils.syncSuppliers();
|
|
await vnUtils.syncConnections();
|
|
if (JSON.parse(env.SYNC_TRADEITEM)) await vnUtils.syncTradeItems();
|
|
} catch (err) {
|
|
vnUtils.criticalError(err);
|
|
}
|
|
}
|
|
|
|
async schedule() {
|
|
try{
|
|
if (moment().isAfter(await vnUtils.getCurrentTokenExpiration())) {
|
|
this.tokenExpirationDate = await vnUtils.getClientToken(models);
|
|
}
|
|
await vnUtils.syncSupplyLines();
|
|
|
|
} catch (err) {
|
|
throw(err);
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Floriday; |