avoid CrashLoopBackOff by sleeping after sending E-Mail

This commit is contained in:
Christopher Hase 2025-03-26 12:44:42 +01:00
parent 574ef51ebd
commit 0c32957d7f
2 changed files with 32 additions and 21 deletions

View file

@ -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"
#CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"

View file

@ -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" <test@example.com>',
to: "Christopher.Hase@telekom.com;test@mailhog.local",
subject: "Horoscope from MailHog",
text: content,
html: "<p> ${content} </p>"
});
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" <test@example.com>',
to: "Christopher.Hase@telekom.com;test@mailhog.local",
subject: "Horoscope from MailHog",
text: content,
html: "<p> ${content} </p>"
});
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);
}