Refactor TED scraper job function for improved readability and maintainability

This commit is contained in:
Nima Nakhostin
2025-12-13 12:35:58 +03:30
parent 6e4b3910ff
commit e4da3b5bb2
+14 -12
View File
@@ -100,20 +100,22 @@ func InitTEDScraper(config Config, mongoManager *mongo.ConnectionManager, appLog
// start TED scraper job with error handling
scheduler := schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo)
function := func() {
ctx := context.Background()
err := tedScraper.Run(ctx, nil, nil)
if err != nil {
appLogger.Error("Scheduled scraper run failed", map[string]interface{}{
"error": err.Error(),
})
// Don't exit - continue running for next scheduled execution
} else {
appLogger.Info("Scheduled scraper run completed successfully", map[string]interface{}{})
}
}
err := scheduler.AddJob(schedule.Job{
Name: "TED Scraper Job",
Func: func() {
ctx := context.Background()
err := tedScraper.Run(ctx, nil, nil)
if err != nil {
appLogger.Error("Scheduled scraper run failed", map[string]interface{}{
"error": err.Error(),
})
// Don't exit - continue running for next scheduled execution
} else {
appLogger.Info("Scheduled scraper run completed successfully", map[string]interface{}{})
}
},
Func: function,
Expr: config.TED.ScrapingInterval,
})
if err != nil {