From e4da3b5bb2c5e3f901a6a49cb0e0911771f3a954 Mon Sep 17 00:00:00 2001 From: Nima Nakhostin Date: Sat, 13 Dec 2025 12:35:58 +0330 Subject: [PATCH] Refactor TED scraper job function for improved readability and maintainability --- cmd/scraper/bootstrap/bootstrap.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/scraper/bootstrap/bootstrap.go b/cmd/scraper/bootstrap/bootstrap.go index 1d57a97..7978cac 100644 --- a/cmd/scraper/bootstrap/bootstrap.go +++ b/cmd/scraper/bootstrap/bootstrap.go @@ -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 {