- Cron Completato
This commit is contained in:
@@ -933,7 +933,6 @@ exports.updateAllBook = async (idapp, options) => {
|
|||||||
try {
|
try {
|
||||||
const macro = new Macro(idapp); // Crea un'istanza della classe Macro
|
const macro = new Macro(idapp); // Crea un'istanza della classe Macro
|
||||||
options.idapp = idapp;
|
options.idapp = idapp;
|
||||||
|
|
||||||
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ CronSchema.statics.executeQueryTable = function (idapp, params, user) {
|
|||||||
CronSchema.statics.startJobCron = async function (idapp) {
|
CronSchema.statics.startJobCron = async function (idapp) {
|
||||||
// Esegui un loop su tutti i cron job che trovi per l'idapp specificato
|
// Esegui un loop su tutti i cron job che trovi per l'idapp specificato
|
||||||
const Cron = this;
|
const Cron = this;
|
||||||
|
try {
|
||||||
const cronJobs = await Cron.find({ idapp, active: true });
|
const cronJobs = await Cron.find({ idapp, active: true });
|
||||||
|
|
||||||
// console.log('Check startJobCron...', idapp);
|
// console.log('Check startJobCron...', idapp);
|
||||||
@@ -95,24 +96,30 @@ CronSchema.statics.startJobCron = async function (idapp) {
|
|||||||
if (!mycron.quanteVolteEseguito) mycron.quanteVolteEseguito = 0;
|
if (!mycron.quanteVolteEseguito) mycron.quanteVolteEseguito = 0;
|
||||||
const timesPerDay = mycron.quanteVolteEseguiAlGG || 1;
|
const timesPerDay = mycron.quanteVolteEseguiAlGG || 1;
|
||||||
const startDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
|
const startDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate());
|
||||||
const lastJobDate = new Date(
|
let lastJobDate = null;
|
||||||
|
if (mycron.lastJobStarted) {
|
||||||
|
lastJobDate = new Date(
|
||||||
mycron.lastJobStarted.getFullYear(),
|
mycron.lastJobStarted.getFullYear(),
|
||||||
mycron.lastJobStarted.getMonth(),
|
mycron.lastJobStarted.getMonth(),
|
||||||
mycron.lastJobStarted.getDate()
|
mycron.lastJobStarted.getDate()
|
||||||
);
|
);
|
||||||
const tempooltre = currentDate - mycron.lastJobStarted >= mycron.everyXMinutes * 60 * 1000;
|
}
|
||||||
if (
|
|
||||||
((mycron.quanteVolteEseguito < timesPerDay && startDate.getTime() === lastJobDate.getTime()) ||
|
let tempooltre = currentDate - mycron.lastJobStarted >= mycron.everyXMinutes * 60 * 1000;
|
||||||
startDate.getTime() !== lastJobDate.getTime()) &&
|
const canExecute =
|
||||||
(!mycron.lastJobStarted || tempooltre)
|
(!mycron.lastJobStarted || // se non c'è un ultimo eseguito, esegui
|
||||||
) {
|
tempooltre) && // se è passato il tempo di attesa, esegui
|
||||||
|
(mycron.lastJobStarted && (mycron.quanteVolteEseguito < timesPerDay) || // se non ho ancora raggiunto il numero di esecuzioni al giorno
|
||||||
|
(!lastJobDate || (startDate.getTime() !== lastJobDate.getTime()))); // se non è lo stesso giorno, esegui
|
||||||
|
if (canExecute) {
|
||||||
if (currentDate >= jobTime) {
|
if (currentDate >= jobTime) {
|
||||||
// Execute the function at the scheduled time
|
// Execute the function at the scheduled time
|
||||||
console.log(`Sto eseguendo il Cron Job: ${mycron.nomeFunzioneDbOp} alle ${currentDate.toLocaleTimeString()}`);
|
console.log(`Sto eseguendo il Cron Job: ${mycron.nomeFunzioneDbOp} alle ${currentDate.toLocaleTimeString()}`);
|
||||||
const status = shared_consts.STATUS_JOB.START;
|
const status = shared_consts.STATUS_JOB.START;
|
||||||
if (startDate.getTime() !== lastJobDate.getTime()) {
|
if (!lastJobDate || startDate.getTime() !== lastJobDate.getTime()) {
|
||||||
mycron.quanteVolteEseguito = 0;
|
mycron.quanteVolteEseguito = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const quanteVolteEseguito = mycron.quanteVolteEseguito + 1;
|
const quanteVolteEseguito = mycron.quanteVolteEseguito + 1;
|
||||||
await Cron.findOneAndUpdate(
|
await Cron.findOneAndUpdate(
|
||||||
{ _id: mycron._id },
|
{ _id: mycron._id },
|
||||||
@@ -140,6 +147,10 @@ CronSchema.statics.startJobCron = async function (idapp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error startJobCron:', e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CronSchema.statics.findAllIdApp = async function (idapp) {
|
CronSchema.statics.findAllIdApp = async function (idapp) {
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ class CronMod {
|
|||||||
|
|
||||||
async eseguiDbOp(idapp, mydata, req, res) {
|
async eseguiDbOp(idapp, mydata, req, res) {
|
||||||
|
|
||||||
|
|
||||||
let ris = await User.DbOp(idapp, mydata);
|
let ris = await User.DbOp(idapp, mydata);
|
||||||
|
|
||||||
|
mydata.idapp = idapp;
|
||||||
|
|
||||||
const populate = require("../populate/populate");
|
const populate = require("../populate/populate");
|
||||||
|
|
||||||
const globalTables = require("../tools/globalTables");
|
const globalTables = require("../tools/globalTables");
|
||||||
@@ -77,6 +78,9 @@ class CronMod {
|
|||||||
|
|
||||||
const { updateAllBook } = require("../controllers/articleController");
|
const { updateAllBook } = require("../controllers/articleController");
|
||||||
|
|
||||||
|
console.log('updateAllBooksAndRemoveCanc...');
|
||||||
|
|
||||||
|
|
||||||
mystr = await updateAllBook(idapp, {usaDBGMLocale: false, caricatutti: true, rimuovieventualiCancellati: true});
|
mystr = await updateAllBook(idapp, {usaDBGMLocale: false, caricatutti: true, rimuovieventualiCancellati: true});
|
||||||
|
|
||||||
ris = { mystr };
|
ris = { mystr };
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Macro {
|
|||||||
|
|
||||||
const lavoromassivo = options.caricatutti;
|
const lavoromassivo = options.caricatutti;
|
||||||
if (lavoromassivo) {
|
if (lavoromassivo) {
|
||||||
myjob = await JobsInProgress.addNewJob({ idapp, descr: 'Riaggiorna Articoli', nomeFunzioneDbOp: 'updateAllBook', status: shared_consts.STATUS_JOB.START });
|
myjob = await JobsInProgress.addNewJob({ idapp: options.idapp, descr: 'Riaggiorna Articoli', nomeFunzioneDbOp: 'updateAllBook', status: shared_consts.STATUS_JOB.START });
|
||||||
if (!myjob) {
|
if (!myjob) {
|
||||||
mylog = 'ATTENZIONE! ❌ STAVO GIA ESEGUENDO QUESTO JOB, quindi ESCO !';
|
mylog = 'ATTENZIONE! ❌ STAVO GIA ESEGUENDO QUESTO JOB, quindi ESCO !';
|
||||||
console.error(mylog);
|
console.error(mylog);
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.2.38
|
1.2.39
|
||||||
Reference in New Issue
Block a user