Files
livedash-node/lib/scheduler.ts
Kaj Kowalski cdaa3ea19d feat: initialize project with Next.js, Prisma, and Tailwind CSS
- Add package.json with dependencies and scripts for Next.js and Prisma
- Implement API routes for session management, user authentication, and company configuration
- Create database schema for Company, User, and Session models in Prisma
- Set up authentication with NextAuth and JWT
- Add password reset functionality and user registration endpoint
- Configure Tailwind CSS and PostCSS for styling
- Implement metrics and dashboard settings API endpoints
2025-05-21 20:44:56 +02:00

28 lines
1.4 KiB
TypeScript

// node-cron job to auto-refresh session data every 15 mins
import cron from "node-cron";
import { prisma } from "./prisma";
import { fetchAndParseCsv } from "./csvFetcher";
export function startScheduler() {
cron.schedule("*/15 * * * *", async () => {
const companies = await prisma.company.findMany();
for (const company of companies) {
try {
// @ts-expect-error - Handle type conversion on session import
const sessions = await fetchAndParseCsv(company.csvUrl, company.csvUsername as string | undefined, company.csvPassword as string | undefined);
await prisma.session.deleteMany({ where: { companyId: company.id } });
for (const session of sessions) {
// @ts-expect-error - Proper data mapping would be needed for production
await prisma.session.create({
// @ts-expect-error - We ensure id is present but TypeScript doesn't know
data: { ...session, companyId: company.id, id: session.id || session.sessionId || `sess_${Date.now()}` },
});
}
console.log(`[Scheduler] Refreshed sessions for company: ${company.name}`);
} catch (e) {
console.error(`[Scheduler] Failed for company: ${company.name} - ${e}`);
}
}
});
}