refs #4823 Added new variables to .env

This commit is contained in:
Guillermo Bonet 2023-04-24 12:46:06 +02:00
parent 5a754967ba
commit 90a27c8691
3 changed files with 614 additions and 617 deletions

View File

@ -44,6 +44,8 @@ DB_MAX_CONN_POOL = 40
#GENERAL CONFIG #GENERAL CONFIG
IS_PRODUCTION = false IS_PRODUCTION = false
MS_PRODUCTION_SCHEDULE = 300000
MS_TEST_SCHEDULE = 100000
SECRETS = true SECRETS = true
FORCE_SYNC = true FORCE_SYNC = true
SYNC_SEQUENCE = true SYNC_SEQUENCE = true

View File

@ -7,65 +7,66 @@ import chalk from 'chalk';
// console.log = (...args) => console.info(`${new moment().format('HH:mm:ss')} -`, ...args); // console.log = (...args) => console.info(`${new moment().format('HH:mm:ss')} -`, ...args);
const env = process.env; const env = process.env;
class Floriday { class Floriday {
async start() { async start() {
try { try {
this.tokenExpirationDate = await utils.requestToken(models); this.tokenExpirationDate = await utils.requestToken(models);
if (JSON.parse(env.SYNC_SEQUENCE)) await utils.syncSequence() if (JSON.parse(env.SYNC_SEQUENCE)) await utils.syncSequence()
if (JSON.parse(env.SYNC_SUPPLIER)) await utils.syncSuppliers(); if (JSON.parse(env.SYNC_SUPPLIER)) await utils.syncSuppliers();
if (JSON.parse(env.SYNC_CONN)) await utils.syncConn(); if (JSON.parse(env.SYNC_CONN)) await utils.syncConn();
if (JSON.parse(env.SYNC_TRADEITEM)) await utils.syncTradeItems(); if (JSON.parse(env.SYNC_TRADEITEM)) await utils.syncTradeItems();
} catch (err) { } catch (err) {
utils.criticalError(err); utils.criticalError(err);
} }
await this.troncal() await this.trunk()
} }
async tryConn() { async tryConn() {
try { try {
utils.sleep(env.DB_TIMEOUT_RECONECT); utils.sleep(env.DB_TIMEOUT_RECONECT);
await checkConn(); await checkConn();
await this.schedule(); await this.schedule();
} }
catch (err) { catch (err) {
throw new Error(err); throw new Error(err);
} }
} }
async schedule () { async schedule () {
try { try {
const intervalTime = JSON.parse(env.IS_PRODUCTION) ? 300000 : 5000; const intervalTime = JSON.parse(env.IS_PRODUCTION)
setInterval(async () => { ? env.MS_PRODUCTION_SCHEDULE
try { : env.MS_TEST_SCHEDULE;
await this.troncal(); setInterval(async () => {
} try {
catch (err) { await this.trunk();
await this.tryConn(); }
} catch (err) {
}, intervalTime); await this.tryConn();
} catch (err) { }
throw new Error(err); }, intervalTime);
} } catch (err) {
throw new Error(err);
}
}
} async trunk() {
try{
if (moment().isAfter(await utils.getCurrentTokenExpiration())) {
this.tokenExpirationDate = await utils.requestToken(models);
}
await utils.syncSupplyLines();
async troncal() { // Continuar con todo lo que haga falta realizar en la rutina
try{
if (moment().isAfter(await utils.getCurrentTokenExpiration())) {
this.tokenExpirationDate = await utils.requestToken(models);
}
await utils.syncSupplyLines();
// Continuar con todo lo que haga falta realizar en el evento } catch (err) {
throw new Error(err);
}
}
} catch (err) { async stop() {
throw new Error(err); await closeConn();
} console.log(chalk.dim('Bye, come back soon 👋'))
} }
async stop() {
await closeConn();
console.log(chalk.dim('Bye, come back soon 👋'))
}
} }
export default Floriday; export default Floriday;

1122
utils.js

File diff suppressed because it is too large Load Diff