avoid CrashLoopBackOff by sleeping after sending E-Mail
All checks were successful
ci / build (push) Successful in 1m3s
All checks were successful
ci / build (push) Successful in 1m3s
This commit is contained in:
parent
574ef51ebd
commit
0c32957d7f
2 changed files with 32 additions and 21 deletions
|
@ -27,4 +27,4 @@ COPY --from=rust-build /usr/local/cargo/bin/iching /usr/local/bin/iching
|
||||||
CMD ["npx", "ts-node", "broker.ts"]
|
CMD ["npx", "ts-node", "broker.ts"]
|
||||||
|
|
||||||
#run indefinitely to avoid CrashLoopBackOff
|
#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"
|
51
broker.ts
51
broker.ts
|
@ -20,31 +20,42 @@ exec('iching divine', (error, stdout, stderr) => {
|
||||||
|
|
||||||
console.log(`Send E-Mail`);
|
console.log(`Send E-Mail`);
|
||||||
|
|
||||||
sendEmail(stdout); //TODO: param
|
sendEmail(stdout);
|
||||||
|
|
||||||
|
sleep();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Erstelle den Transporter
|
// Create Transporter
|
||||||
const transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
//host: "localhost", // MailHog läuft standardmäßig auf localhost
|
|
||||||
host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP
|
host: "mailhog.mailhog.svc.cluster.local", // MailHog ClusterIP
|
||||||
port: 1025, // Standard-MailHog SMTP-Port
|
port: 1025, // Standard-MailHog SMTP-Port
|
||||||
secure: false // MailHog benötigt keine Verschlüsselung
|
secure: false // MailHog needs no encryption
|
||||||
});
|
});
|
||||||
|
|
||||||
// E-Mail senden
|
// Send E-Mail
|
||||||
async function sendEmail(content: string) { //TODO: param
|
async function sendEmail(content: string) {
|
||||||
try {
|
try {
|
||||||
const info = await transporter.sendMail({
|
const info = await transporter.sendMail({
|
||||||
from: '"Test Sender" <test@example.com>',
|
from: '"Test Sender" <test@example.com>',
|
||||||
to: "Christopher.Hase@telekom.com;test@mailhog.local",
|
to: "Christopher.Hase@telekom.com;test@mailhog.local",
|
||||||
subject: "Horoscope from MailHog",
|
subject: "Horoscope from MailHog",
|
||||||
text: content,
|
text: content,
|
||||||
html: "<p> ${content} </p>"
|
html: "<p> ${content} </p>"
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("E-Mail sent: ", info.messageId);
|
console.log("E-Mail sent: ", info.messageId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error Sending E-Mail:", 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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue