worker notice limit config

This commit is contained in:
m.nazemi
2026-04-12 21:03:34 +03:30
parent 6aa6022da0
commit a6a1ad51b1
3 changed files with 28 additions and 20 deletions
+5 -3
View File
@@ -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, &notify, noticeRepo, tenderRepo, glmService, scraperService)
appLogger.Info("Starting notice worker", map[string]interface{}{
"processing_limit": config.Worker.NoticeProcessingLimit,
})
noticeWorker := workers.NewNoticeWorker(mongoManager, appLogger, &notify, 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, &notify, noticeRepo, tenderRepo, glmService, scraperService)
worker := workers.NewNoticeWorker(mongoManager, appLogger, &notify, noticeRepo, tenderRepo, glmService, scraperService, config.Worker.NoticeProcessingLimit)
worker.Run()
},
Expr: workerInterval,
+2 -1
View File
@@ -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 {
+21 -16
View File
@@ -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)