Adding Health Check for cloud providers

This commit is contained in:
Yanis JEDRZEJCZAK 2024-05-14 17:11:56 +02:00
parent 0584e71439
commit 6c9eb6fec9

View File

@ -4,12 +4,23 @@ import "reflect-metadata";
import { Container } from "typedi";
import { BackendVariables } from "@Common/config/variables/Variables";
import CronService from "@Services/common/CronService/CronService";
import http from "http";
(async () => {
console.info("Cron started");
try {
const variables = await Container.get(BackendVariables).validate();
/**
* Cloud providers needs a health check endpoint to know if the server is up otherwise they will stop the app
*/
http.createServer((_req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Health check: OK');
res.end();
}).listen(variables.APP_PORT);
Container.get(CronService).archiveFiles();
await Container.get(CronService).updateUsers();
Container.get(CronService).checkDocumentsExpiration();
@ -17,6 +28,7 @@ import CronService from "@Services/common/CronService/CronService";
Container.get(CronService).sendMails();
Container.get(CronService).sendRecapMails();
}
} catch (e) {
console.error(e);
}