Enhance TED Scraper Initialization and Error Handling

- Updated the InitTEDScraper function to return a scheduler instance, allowing for better error handling during initialization.
- Added error logging for failed scheduler initialization and job scheduling, improving robustness.
- Implemented graceful shutdown for the scheduler in the main function, ensuring proper resource management during application termination.
This commit is contained in:
Nima Nakhostin
2025-11-29 10:21:35 +03:30
parent e2e9159ac3
commit bb974ad1ce
2 changed files with 37 additions and 48 deletions
+10 -1
View File
@@ -73,7 +73,11 @@ func main() {
}
// Initialize TED scraper for scheduled mode
bootstrap.InitTEDScraper(*config, mongoManager, appLogger, notificationService)
scheduler := bootstrap.InitTEDScraper(*config, mongoManager, appLogger, notificationService)
if scheduler == nil {
appLogger.Error("Failed to initialize TED scraper scheduler", map[string]interface{}{})
os.Exit(1)
}
// Set up signal handling for graceful shutdown
signalChan := make(chan os.Signal, 1)
@@ -83,5 +87,10 @@ func main() {
<-signalChan
appLogger.Info("Received shutdown signal, stopping scheduler...", map[string]interface{}{})
// Stop scheduler gracefully
if scheduler != nil {
scheduler.Stop()
}
appLogger.Info("TED scraper application stopped", map[string]interface{}{})
}