push notificaitons

This commit is contained in:
toni
2026-03-16 00:46:30 +01:00
parent 2620538a2c
commit e3184be911
20 changed files with 237 additions and 253 deletions
+45 -2
View File
@@ -1,5 +1,6 @@
import constants from "constants";
import cors from "cors";
import { CronJob } from "cron";
import express, {
type NextFunction,
type Request,
@@ -11,7 +12,9 @@ import { RegisterRoutes } from "./generated/routes.js";
import { inject } from "./infrastructure/di/injector.js";
import { sessionHandler } from "./infrastructure/sessionHandler.js";
import { EnvironmentService } from "./services/environmentService.js";
import { FoundEventsService } from "./services/foundEvents/foundEventsService.js";
import { KeycloakUser } from "./services/keycloak/user/keycloak-user.js";
import { PushService } from "./services/push/pushService.js";
// import helmet from "helmet";
// TODO import http2 from 'http2';
@@ -67,12 +70,13 @@ async function run() {
// key = fs.readFileSync("src/key.pem");
port = 3000;
app.listen(port, error => {
const server = app.listen(port, error => {
if (error) {
console.error("Startup crashed:", error);
}
console.log(`Server is running at http://localhost:${port}`);
});
server.on("close", () => stopCron());
} else {
port = 5443;
const SSL_CERT_PATH = process.env["SSL_CERT_PATH"];
@@ -100,17 +104,56 @@ async function run() {
constants.SSL_OP_NO_SSLv2 |
constants.SSL_OP_NO_SSLv3,
};
https.createServer(sslOptions, app).listen(port, () => {
const server = https.createServer(sslOptions, app).listen(port, () => {
console.log(`Server is running on port ${port}`);
});
server.on("close", () => stopCron());
}
// const h2SslOptions={};
// http2.createServer(h2SslOptions, app).listen(port, ()=>{
// console.log(`HTTP/2 server is running on port ${port}`);
// })
initJobs();
startCron();
console.log("setup done");
}
const jobs: CronJob[] = [];
function initJobs() {
const eventsService = inject(FoundEventsService);
const crawlJob = CronJob.from({
cronTime: "35 4 * * *",
onTick: async () => {
await eventsService.crawl();
},
});
jobs.push(crawlJob);
const pushService = inject(PushService);
const notifyJob = CronJob.from({
cronTime: "10 12 * * *",
onTick: async () => {
await pushService.sendEventNotifications();
},
});
jobs.push(notifyJob);
}
function startCron() {
console.log("starting jobs");
for (const job of jobs) {
job.start();
}
}
async function stopCron() {
console.log("stopping jobs");
for (const job of jobs) {
job.stop();
}
}
run();