worker notice limit config
This commit is contained in:
@@ -90,8 +90,10 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
|
|||||||
tenderRepo := tender.NewRepository(mongoManager, appLogger)
|
tenderRepo := tender.NewRepository(mongoManager, appLogger)
|
||||||
|
|
||||||
// Initialize Notice Worker
|
// Initialize Notice Worker
|
||||||
appLogger.Info("Starting notice worker", map[string]interface{}{})
|
appLogger.Info("Starting notice worker", map[string]interface{}{
|
||||||
noticeWorker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService)
|
"processing_limit": config.Worker.NoticeProcessingLimit,
|
||||||
|
})
|
||||||
|
noticeWorker := workers.NewNoticeWorker(mongoManager, appLogger, ¬ify, noticeRepo, tenderRepo, glmService, scraperService, config.Worker.NoticeProcessingLimit)
|
||||||
noticeWorker.Run()
|
noticeWorker.Run()
|
||||||
|
|
||||||
// Initialize Queue-based scraping if enabled
|
// 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{
|
schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{
|
||||||
Name: "Notice Worker Job",
|
Name: "Notice Worker Job",
|
||||||
Func: func() {
|
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()
|
worker.Run()
|
||||||
},
|
},
|
||||||
Expr: workerInterval,
|
Expr: workerInterval,
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ type QueueConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WorkerConfig 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 {
|
type GLMConfig struct {
|
||||||
|
|||||||
@@ -18,24 +18,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NoticeWorker struct {
|
type NoticeWorker struct {
|
||||||
Mongo *mongo.ConnectionManager
|
Mongo *mongo.ConnectionManager
|
||||||
Logger logger.Logger
|
Logger logger.Logger
|
||||||
Notify *notification.SDK
|
Notify *notification.SDK
|
||||||
NoticeRepo notice.Repository
|
NoticeRepo notice.Repository
|
||||||
TenderRepo tender.TenderRepository
|
TenderRepo tender.TenderRepository
|
||||||
GLM *glm.SDK
|
GLM *glm.SDK
|
||||||
Scraper scraper.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{
|
return &NoticeWorker{
|
||||||
Mongo: mongo,
|
Mongo: mongo,
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
Notify: notify,
|
Notify: notify,
|
||||||
NoticeRepo: noticeRepo,
|
NoticeRepo: noticeRepo,
|
||||||
TenderRepo: tenderRepo,
|
TenderRepo: tenderRepo,
|
||||||
GLM: glmService,
|
GLM: glmService,
|
||||||
Scraper: scraper,
|
Scraper: scraper,
|
||||||
|
ProcessingLimit: processingLimit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +105,7 @@ func (w *NoticeWorker) Run() {
|
|||||||
limit := 10
|
limit := 10
|
||||||
skip := 0
|
skip := 0
|
||||||
processedCount := 0
|
processedCount := 0
|
||||||
maxToProcess := 5 // Limit processing to allow scraper worker to run
|
maxToProcess := w.ProcessingLimit
|
||||||
|
|
||||||
for processedCount < maxToProcess {
|
for processedCount < maxToProcess {
|
||||||
notices, _, err := w.NoticeRepo.GetUnProcessedNotices(context.Background(), limit, skip)
|
notices, _, err := w.NoticeRepo.GetUnProcessedNotices(context.Background(), limit, skip)
|
||||||
|
|||||||
Reference in New Issue
Block a user