Add mantis summaries and start of email summaries... Need to figure out a way to get the emails since MS block IMAP :(

This commit is contained in:
Cameron Redmore 2025-04-23 21:12:08 +01:00
parent 2d11d0bd79
commit 2ad9a63582
18 changed files with 1993 additions and 577 deletions

View file

@ -19,9 +19,10 @@ import {
defineSsrRenderPreloadTag
} from '#q-app/wrappers'
// Import database initialization and close function
import { initializeDatabase, closeDatabase } from './database.js';
import prisma from './database.js'; // Import the prisma client instance
import apiRoutes from './routes/api.js';
import cron from 'node-cron';
import { generateAndStoreMantisSummary } from './services/mantisSummarizer.js';
/**
* Create your webserver and return its instance.
@ -35,12 +36,31 @@ export const create = defineSsrCreate((/* { ... } */) => {
// Initialize the database (now synchronous)
try {
initializeDatabase();
console.log('Database initialized successfully.');
console.log('Prisma Client is ready.'); // Log Prisma readiness
// Schedule the Mantis summary task after DB initialization
// Run daily at 1:00 AM server time (adjust as needed)
cron.schedule('0 1 * * *', async () => {
console.log('Running scheduled Mantis summary task...');
try {
await generateAndStoreMantisSummary();
console.log('Scheduled Mantis summary task completed.');
} catch (error) {
console.error('Error running scheduled Mantis summary task:', error);
}
}, {
scheduled: true,
timezone: "Europe/London" // Example: Set to your server's timezone
});
console.log('Mantis summary cron job scheduled.');
// Optional: Run once immediately on server start if needed
generateAndStoreMantisSummary().catch(err => console.error('Initial Mantis summary failed:', err));
} catch (error) {
console.error('Failed to initialize database:', error);
console.error('Error during server setup:', error);
// Optionally handle the error more gracefully, e.g., prevent server start
process.exit(1); // Exit if DB connection fails
process.exit(1); // Exit if setup fails
}
// attackers can use this header to detect apps running Express
@ -91,9 +111,14 @@ export const listen = defineSsrListen(({ app, devHttpsApp, port }) => {
*
* Can be async: defineSsrClose(async ({ ... }) => { ... })
*/
export const close = defineSsrClose(({ listenResult }) => {
export const close = defineSsrClose(async ({ listenResult }) => {
// Close the database connection when the server shuts down
closeDatabase();
try {
await prisma.$disconnect();
console.log('Prisma Client disconnected.');
} catch (e) {
console.error('Error disconnecting Prisma Client:', e);
}
return listenResult.close()
})