mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 09:52:09 +01:00
- Added processingScheduler.js and processingScheduler.ts to handle session transcript processing using OpenAI API. - Implemented a new scheduler (scheduler.js and schedulers.ts) for refreshing sessions every 15 minutes. - Updated Prisma migrations to add new fields for processed sessions, including questions, sentimentCategory, and summary. - Created scripts (process_sessions.mjs and process_sessions.ts) for manual processing of unprocessed sessions. - Enhanced server.js and server.mjs to initialize schedulers on server start.
36 lines
987 B
JavaScript
36 lines
987 B
JavaScript
// Session refresh scheduler - JavaScript version
|
|
import cron from "node-cron";
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { fetchAndStoreSessionsForAllCompanies } from "./csvFetcher.js";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
/**
|
|
* Refresh sessions for all companies
|
|
*/
|
|
async function refreshSessions() {
|
|
console.log("[Scheduler] Starting session refresh...");
|
|
try {
|
|
await fetchAndStoreSessionsForAllCompanies();
|
|
console.log("[Scheduler] Session refresh completed successfully.");
|
|
} catch (error) {
|
|
console.error("[Scheduler] Error during session refresh:", error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Start the session refresh scheduler
|
|
*/
|
|
export function startScheduler() {
|
|
// Run every 15 minutes
|
|
cron.schedule("*/15 * * * *", async () => {
|
|
try {
|
|
await refreshSessions();
|
|
} catch (error) {
|
|
console.error("[Scheduler] Error in scheduler:", error);
|
|
}
|
|
});
|
|
|
|
console.log("[Scheduler] Started session refresh scheduler (runs every 15 minutes).");
|
|
}
|