import dotenv from 'dotenv'; dotenv.config(); import WorkflowOrchestrator from './workflows/WorkflowOrchestrator'; import rDramaSession from './rdrama/session/SessionManager'; import redditSession from './reddit/session/SessionManager'; import { DatabaseInitializer } from './db/initializeDatabase'; import { DatabaseService } from './db/services/Database'; import { DatabaseMaintenanceService } from './db/services/DatabaseMaintenance'; // Import other necessary services or configurations async function startApplication() { console.log('Database Start') const databaseInitializer = DatabaseInitializer.getInstance(); const db = await databaseInitializer.getDbInstance() if (!db) { throw new Error('Failed to initialize the database.'); } const canSend = await DatabaseService.canSendNotification(); const coolDownHours = process.env.NOTIFICATION_COOLDOWN_HOURS if (!canSend) { console.log(`Last Message Sent less than ${coolDownHours ? coolDownHours : 4} hours ago. Set NOTIFICATION_COOLDOWN_HOURS to change this`) return; } console.log('RDrama Session Start') // Initialize SessionManager or other global configurations const rDramaSessionManager = rDramaSession.getInstance(); if (!process.env.RDRAMA_API_KEY) { throw new Error('RDRAMA_API_KEY is undefined. Please set this environment variable.'); } rDramaSessionManager.setAuthorizationToken(process.env.RDRAMA_API_KEY); console.log('Database Maintenance Start') const databaseMaintenance = new DatabaseMaintenanceService() await databaseMaintenance.runMaintenanceTasks() console.log('Reddit Session Start') await redditSession.getInstance() // Initialize and start your workflow const workflowOrchestrator = new WorkflowOrchestrator(); await workflowOrchestrator.executeWorkflow(); await rDramaSessionManager.shutdown() } startApplication() .then(() => console.log('Application started successfully.')) .catch((error) => console.error('Application failed to start:', error));