From a6a1ad51b1fac95c971b695694026b103b4c24cf Mon Sep 17 00:00:00 2001 From: "m.nazemi" Date: Sun, 12 Apr 2026 21:03:34 +0330 Subject: [PATCH] worker notice limit config --- cmd/worker/bootstrap/bootstrap.go | 8 ++++--- cmd/worker/bootstrap/config.go | 3 ++- cmd/worker/workers/notice.go | 37 ++++++++++++++++++------------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/cmd/worker/bootstrap/bootstrap.go b/cmd/worker/bootstrap/bootstrap.go index 888eee8..9768096 100644 --- a/cmd/worker/bootstrap/bootstrap.go +++ b/cmd/worker/bootstrap/bootstrap.go @@ -90,8 +90,10 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger tenderRepo := tender.NewRepository(mongoManager, appLogger) // Initialize Notice Worker - appLogger.Info("Starting notice worker", map[string]interface{}{}) - noticeWorker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService) + appLogger.Info("Starting notice worker", map[string]interface{}{ + "processing_limit": config.Worker.NoticeProcessingLimit, + }) + noticeWorker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService, config.Worker.NoticeProcessingLimit) noticeWorker.Run() // Initialize Queue-based scraping if enabled @@ -207,7 +209,7 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{ Name: "Notice Worker Job", Func: func() { - worker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService) + worker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService, config.Worker.NoticeProcessingLimit) worker.Run() }, Expr: workerInterval, diff --git a/cmd/worker/bootstrap/config.go b/cmd/worker/bootstrap/config.go index fbb9d05..08358c8 100644 --- a/cmd/worker/bootstrap/config.go +++ b/cmd/worker/bootstrap/config.go @@ -35,7 +35,8 @@ type QueueConfig struct { } type WorkerConfig struct { - Interval string `env:"WORKER_INTERVAL" envDefault:"* 10 * * * *"` + Interval string `env:"WORKER_INTERVAL" envDefault:"* 10 * * * *"` + NoticeProcessingLimit int `env:"WORKER_NOTICE_PROCESSING_LIMIT" envDefault:"5"` } type GLMConfig struct { diff --git a/cmd/worker/workers/notice.go b/cmd/worker/workers/notice.go index 8dbbe91..119b4e3 100644 --- a/cmd/worker/workers/notice.go +++ b/cmd/worker/workers/notice.go @@ -18,24 +18,29 @@ import ( ) type NoticeWorker struct { - Mongo *mongo.ConnectionManager - Logger logger.Logger - Notify *notification.SDK - NoticeRepo notice.Repository - TenderRepo tender.TenderRepository - GLM *glm.SDK - Scraper scraper.SDK + Mongo *mongo.ConnectionManager + Logger logger.Logger + Notify *notification.SDK + NoticeRepo notice.Repository + TenderRepo tender.TenderRepository + GLM *glm.SDK + Scraper scraper.SDK + ProcessingLimit int } -func NewNoticeWorker(mongo *mongo.ConnectionManager, logger logger.Logger, notify *notification.SDK, noticeRepo notice.Repository, tenderRepo tender.TenderRepository, glmService *glm.SDK, scraper scraper.SDK) *NoticeWorker { +func NewNoticeWorker(mongo *mongo.ConnectionManager, logger logger.Logger, notify *notification.SDK, noticeRepo notice.Repository, tenderRepo tender.TenderRepository, glmService *glm.SDK, scraper scraper.SDK, processingLimit int) *NoticeWorker { + if processingLimit <= 0 { + processingLimit = 5 // Default limit + } return &NoticeWorker{ - Mongo: mongo, - Logger: logger, - Notify: notify, - NoticeRepo: noticeRepo, - TenderRepo: tenderRepo, - GLM: glmService, - Scraper: scraper, + Mongo: mongo, + Logger: logger, + Notify: notify, + NoticeRepo: noticeRepo, + TenderRepo: tenderRepo, + GLM: glmService, + Scraper: scraper, + ProcessingLimit: processingLimit, } } @@ -100,7 +105,7 @@ func (w *NoticeWorker) Run() { limit := 10 skip := 0 processedCount := 0 - maxToProcess := 5 // Limit processing to allow scraper worker to run + maxToProcess := w.ProcessingLimit for processedCount < maxToProcess { notices, _, err := w.NoticeRepo.GetUnProcessedNotices(context.Background(), limit, skip)