36 lines
1013 B
TypeScript
36 lines
1013 B
TypeScript
import "module-alias/register";
|
|
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();
|
|
if (variables.ENV !== "dev") {
|
|
Container.get(CronService).sendMails();
|
|
Container.get(CronService).sendRecapMails();
|
|
}
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
})();
|