diff --git a/Dockerfile b/Dockerfile index 99a7a86..93b3713 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,4 +27,4 @@ COPY --from=rust-build /usr/local/cargo/bin/iching /usr/local/bin/iching CMD ["npx", "ts-node", "broker.ts"] #run indefinitely to avoid CrashLoopBackOff -CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" \ No newline at end of file +#CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait" \ No newline at end of file diff --git a/broker.ts b/broker.ts index 8fb2a05..0e2652f 100644 --- a/broker.ts +++ b/broker.ts @@ -20,31 +20,42 @@ exec('iching divine', (error, stdout, stderr) => { console.log(`Send E-Mail`); - sendEmail(stdout); //TODO: param + sendEmail(stdout); + + sleep(); }); -// Erstelle den Transporter +// Create Transporter const transporter = nodemailer.createTransport({ - //host: "localhost", // MailHog läuft standardmäßig auf localhost host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP port: 1025, // Standard-MailHog SMTP-Port - secure: false // MailHog benötigt keine Verschlüsselung - }); + secure: false // MailHog needs no encryption +}); - // E-Mail senden - async function sendEmail(content: string) { //TODO: param - try { - const info = await transporter.sendMail({ - from: '"Test Sender" ', - to: "Christopher.Hase@telekom.com;test@mailhog.local", - subject: "Horoscope from MailHog", - text: content, - html: "

${content}

" - }); - - console.log("E-Mail sent: ", info.messageId); - } catch (error) { - console.error("Error Sending E-Mail:", error); - } +// Send E-Mail +async function sendEmail(content: string) { + try { + const info = await transporter.sendMail({ + from: '"Test Sender" ', + to: "Christopher.Hase@telekom.com;test@mailhog.local", + subject: "Horoscope from MailHog", + text: content, + html: "

${content}

" + }); + + console.log("E-Mail sent: ", info.messageId); + } catch (error) { + console.error("Error Sending E-Mail:", error); } +} + +//Sleep. To avoid: Completed -> Terminated -> CrashLoopBackOff +async function sleep() { + console.log("Go to sleep: ", new Date().toISOString()); + + // sleep 1h (3600000 ms) + setTimeout(() => { + sleep(); // recursion after 1h + }, 3600000); +} \ No newline at end of file