refs #4823 Added new variables to .env
This commit is contained in:
parent
5a754967ba
commit
90a27c8691
|
@ -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
|
||||||
|
|
13
floriday.js
13
floriday.js
|
@ -17,7 +17,7 @@ class Floriday {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
utils.criticalError(err);
|
utils.criticalError(err);
|
||||||
}
|
}
|
||||||
await this.troncal()
|
await this.trunk()
|
||||||
}
|
}
|
||||||
|
|
||||||
async tryConn() {
|
async tryConn() {
|
||||||
|
@ -33,10 +33,12 @@ class Floriday {
|
||||||
|
|
||||||
async schedule () {
|
async schedule () {
|
||||||
try {
|
try {
|
||||||
const intervalTime = JSON.parse(env.IS_PRODUCTION) ? 300000 : 5000;
|
const intervalTime = JSON.parse(env.IS_PRODUCTION)
|
||||||
|
? env.MS_PRODUCTION_SCHEDULE
|
||||||
|
: env.MS_TEST_SCHEDULE;
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
await this.troncal();
|
await this.trunk();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
await this.tryConn();
|
await this.tryConn();
|
||||||
|
@ -45,17 +47,16 @@ class Floriday {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async troncal() {
|
async trunk() {
|
||||||
try{
|
try{
|
||||||
if (moment().isAfter(await utils.getCurrentTokenExpiration())) {
|
if (moment().isAfter(await utils.getCurrentTokenExpiration())) {
|
||||||
this.tokenExpirationDate = await utils.requestToken(models);
|
this.tokenExpirationDate = await utils.requestToken(models);
|
||||||
}
|
}
|
||||||
await utils.syncSupplyLines();
|
await utils.syncSupplyLines();
|
||||||
|
|
||||||
// Continuar con todo lo que haga falta realizar en el evento
|
// Continuar con todo lo que haga falta realizar en la rutina
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
|
|
24
utils.js
24
utils.js
|
@ -185,13 +185,15 @@ export async function asyncQueue(fnArray, concurrency = 1) {
|
||||||
export async function syncSequence(current = 0, model = null , maximumSequenceNumber = 0){
|
export async function syncSequence(current = 0, model = null , maximumSequenceNumber = 0){
|
||||||
if (model == null && current == 0){
|
if (model == null && current == 0){
|
||||||
try {
|
try {
|
||||||
|
const spinner = ora(`Syncing sequence...`).start();
|
||||||
let mockModels = [
|
let mockModels = [
|
||||||
'suppliers',
|
'suppliers',
|
||||||
'tradeItems',
|
'tradeItems',
|
||||||
'supplyLines',
|
'supplyLines',
|
||||||
];
|
];
|
||||||
const spinner = ora(`Syncing sequence...`).start();
|
let i = 1;
|
||||||
for (let mockModel in mockModels) {
|
for (let mockModel in mockModels) {
|
||||||
|
spinner.text = `Syncing ${i++} sequences...`
|
||||||
const element = mockModels[mockModel];
|
const element = mockModels[mockModel];
|
||||||
await syncSequence(0, element);
|
await syncSequence(0, element);
|
||||||
}
|
}
|
||||||
|
@ -201,9 +203,7 @@ export async function syncSequence(current = 0, model = null , maximumSequenceNu
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}
|
}
|
||||||
} else if (current) {
|
} else if (current) {
|
||||||
|
|
||||||
let tx = await models.sequelize.transaction();
|
let tx = await models.sequelize.transaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let sequence = await models.sequenceNumber.findOrCreate({
|
let sequence = await models.sequenceNumber.findOrCreate({
|
||||||
where: {
|
where: {
|
||||||
|
@ -364,7 +364,6 @@ export async function syncConn(){
|
||||||
organizationId: connection.organizationId
|
organizationId: connection.organizationId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
spinner.succeed();
|
spinner.succeed();
|
||||||
|
@ -377,10 +376,9 @@ export async function syncConn(){
|
||||||
export async function syncTradeItems(){
|
export async function syncTradeItems(){
|
||||||
const spinner = ora(`Syncing trade items...`).start();
|
const spinner = ora(`Syncing trade items...`).start();
|
||||||
const suppliers = await models.supplier.findAll();
|
const suppliers = await models.supplier.findAll();
|
||||||
let i = 0;
|
let i = 1;
|
||||||
|
let x = 1;
|
||||||
for (let supplier of suppliers) {
|
for (let supplier of suppliers) {
|
||||||
i++;
|
|
||||||
|
|
||||||
if (!supplier.isConnected) continue;
|
if (!supplier.isConnected) continue;
|
||||||
|
|
||||||
let query = `${url}/trade-items?supplierOrganizationId=${supplier.organizationId}`;
|
let query = `${url}/trade-items?supplierOrganizationId=${supplier.organizationId}`;
|
||||||
|
@ -390,7 +388,6 @@ export async function syncTradeItems(){
|
||||||
'X-Api-Key': process.env.API_KEY
|
'X-Api-Key': process.env.API_KEY
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
|
|
||||||
let request = await fetch(query, {
|
let request = await fetch(query, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers
|
headers
|
||||||
|
@ -398,25 +395,22 @@ export async function syncTradeItems(){
|
||||||
|
|
||||||
let tradeItems = await request.json();
|
let tradeItems = await request.json();
|
||||||
|
|
||||||
if (!tradeItems.length) {
|
if (!tradeItems.length)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
for (let tradeItem of tradeItems) {
|
for (let tradeItem of tradeItems) {
|
||||||
|
|
||||||
await insertItem(tradeItem, supplier);
|
await insertItem(tradeItem, supplier);
|
||||||
|
spinner.text = `Syncing ${x++} suppliers`
|
||||||
}
|
};
|
||||||
|
|
||||||
console.log('Synced trade items for: ', supplier.commercialName);
|
console.log('Synced trade items for: ', supplier.commercialName);
|
||||||
console.log('Remaining suppliers: ', suppliers.length - i, 'of', suppliers.length);
|
console.log('Remaining suppliers: ', suppliers.length - i++, 'of', suppliers.length);
|
||||||
console.log('Total trade items: ', tradeItems.length);
|
console.log('Total trade items: ', tradeItems.length);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
spinner.fail();
|
spinner.fail();
|
||||||
console.log('Error while syncing trade items for: ', supplier.commercialName);
|
console.log('Error while syncing trade items for: ', supplier.commercialName);
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
spinner.succeed()
|
spinner.succeed()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue