From d4a86547d16de7cf19ef895a7df9ef9af2b8a025 Mon Sep 17 00:00:00 2001 From: Christopher Hase Date: Fri, 28 Mar 2025 13:40:48 +0100 Subject: [PATCH] schedule next run part 4 --- broker.ts | 60 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/broker.ts b/broker.ts index 331fbde..bb278b4 100644 --- a/broker.ts +++ b/broker.ts @@ -17,42 +17,45 @@ const transporter = nodemailer.createTransport({ secure: false // MailHog needs no encryption }); -exec('iching divine', (error, stdout, stderr) => { +function executeCommand(): void { - console.log(`Begin`); + exec('iching divine', (error, stdout, stderr) => { - if (error) { - console.error(`Error: ${error.message}`); - return; - } + console.log(`Begin`); - if (stderr) { - console.error(`Stderr: ${stderr}`); - return; - } + if (error) { + console.error(`Error: ${error.message}`); + return; + } - console.log(`Send E-Mail`); + if (stderr) { + console.error(`Stderr: ${stderr}`); + return; + } - sendEmail(stdout); + console.log(`Send E-Mail`); - if (config == undefined) { - config = loadConfig(); - } else { //TODO: JUST FOR DEBUGGING - console.log(`Config already read...`); - } + sendEmail(stdout); - console.log(config.daysInterval, config.timeOfDay); + if (config == undefined) { + config = loadConfig(); + } else { //TODO: JUST FOR DEBUGGING + console.log(`Config already read...`); + } - //sleep(); + console.log(config.daysInterval, config.timeOfDay); - // Berechne das nächste Ausführungsdatum - const nextRunDate = calculateNextRunDate(config.daysInterval, config.timeOfDay); - console.log(`Gegenwärtig: ` + new Date()); - console.log(`Nächste Ausführung: ${nextRunDate}`); + //sleep(); - // Starte das Scheduling - scheduleNextRun(nextRunDate); -}); + // Berechne das nächste Ausführungsdatum + const nextRunDate = calculateNextRunDate(config.daysInterval, config.timeOfDay); + console.log(`Gegenwärtig: ` + new Date()); + console.log(`Nächste Ausführung: ${nextRunDate}`); + + // Starte das Scheduling + scheduleNextRun(nextRunDate); + }); +} // Funktion, um die Konfiguration zu laden function loadConfig(): Config { @@ -110,7 +113,7 @@ function calculateNextRunDate(daysInterval: number, timeOfDay: string): Date { return currentDate;*/ - currentDate.setMinutes(currentDate.getMinutes() + 2); //TODO: JUST FOR DEBUGGING!!! + currentDate.setMinutes(currentDate.getMinutes() + 1); //TODO: JUST FOR DEBUGGING!!! return currentDate; } @@ -124,7 +127,8 @@ function scheduleNextRun(nextRunDate: Date) { // Hier wird der Prozess ausgeführt console.log('Prozess wird ausgeführt!'); - exec('iching divine'); //TODO: ÜBERPRÜFEN!!! + //exec('iching divine'); //TODO: ÜBERPRÜFEN!!! + executeCommand(); // Berechne das nächste Ausführungsdatum und plane es erneut const newNextRunDate = calculateNextRunDate(config.daysInterval, config.timeOfDay);