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,19 +20,20 @@ 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
// Send E-Mail
async function sendEmail(content: string) {
try {
const info = await transporter.sendMail({
from: '"Test Sender" <test@example.com>',
@ -48,3 +49,13 @@ const transporter = nodemailer.createTransport({
}
}
//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);
}