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