2024-02-22 06:15:16 +00:00
|
|
|
import dotenv from 'dotenv';
|
|
|
|
dotenv.config();
|
|
|
|
|
2024-02-23 06:18:00 +00:00
|
|
|
import WorkflowOrchestrator from './workflows/WorkflowOrchestrator';
|
2024-03-02 07:41:11 +00:00
|
|
|
import rDramaSession from './rdrama/session/SessionManager';
|
|
|
|
import redditSession from './reddit/session/SessionManager';
|
2024-02-23 07:02:46 +00:00
|
|
|
import { DatabaseInitializer } from './db/initializeDatabase';
|
2024-02-27 06:39:51 +00:00
|
|
|
import { DatabaseService } from './db/services/Database';
|
|
|
|
import { DatabaseMaintenanceService } from './db/services/DatabaseMaintenance';
|
2024-02-23 06:18:00 +00:00
|
|
|
// Import other necessary services or configurations
|
2024-02-22 06:15:16 +00:00
|
|
|
|
2024-02-23 06:18:00 +00:00
|
|
|
async function startApplication() {
|
2024-03-05 06:25:05 +00:00
|
|
|
console.log('Database Start')
|
|
|
|
const databaseInitializer = DatabaseInitializer.getInstance();
|
|
|
|
const db = await databaseInitializer.getDbInstance()
|
|
|
|
if (!db) {
|
|
|
|
throw new Error('Failed to initialize the database.');
|
|
|
|
}
|
2024-03-07 06:52:44 +00:00
|
|
|
const canSend = await DatabaseService.canSendNotification();
|
2024-03-05 06:25:05 +00:00
|
|
|
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`)
|
2024-03-06 05:17:42 +00:00
|
|
|
return;
|
2024-03-05 06:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('RDrama Session Start')
|
2024-02-23 06:18:00 +00:00
|
|
|
// Initialize SessionManager or other global configurations
|
2024-03-02 07:41:11 +00:00
|
|
|
const rDramaSessionManager = rDramaSession.getInstance();
|
2024-02-23 06:18:00 +00:00
|
|
|
if (!process.env.RDRAMA_API_KEY) {
|
|
|
|
throw new Error('RDRAMA_API_KEY is undefined. Please set this environment variable.');
|
|
|
|
}
|
2024-03-02 07:41:11 +00:00
|
|
|
rDramaSessionManager.setAuthorizationToken(process.env.RDRAMA_API_KEY);
|
2024-02-23 06:18:00 +00:00
|
|
|
|
2024-02-27 05:11:00 +00:00
|
|
|
console.log('Database Maintenance Start')
|
2024-03-07 06:52:44 +00:00
|
|
|
const databaseMaintenance = new DatabaseMaintenanceService()
|
2024-02-27 05:11:00 +00:00
|
|
|
await databaseMaintenance.runMaintenanceTasks()
|
2024-02-23 07:02:46 +00:00
|
|
|
|
2024-03-05 06:25:05 +00:00
|
|
|
console.log('Reddit Session Start')
|
2024-03-07 06:52:44 +00:00
|
|
|
await redditSession.getInstance()
|
2024-03-02 07:41:11 +00:00
|
|
|
|
2024-02-23 06:18:00 +00:00
|
|
|
// Initialize and start your workflow
|
2024-03-09 07:34:45 +00:00
|
|
|
const workflowOrchestrator = new WorkflowOrchestrator();
|
2024-02-23 06:18:00 +00:00
|
|
|
await workflowOrchestrator.executeWorkflow();
|
|
|
|
}
|
|
|
|
|
|
|
|
startApplication()
|
|
|
|
.then(() => console.log('Application started successfully.'))
|
|
|
|
.catch((error) => console.error('Application failed to start:', error));
|