removed filter to get all tenders - bug fix

This commit is contained in:
Mazyar
2026-05-04 05:28:56 +03:30
parent 446c11dfbf
commit 086fe0ffd5
7 changed files with 31 additions and 20 deletions
+13 -4
View File
@@ -77,7 +77,7 @@ func InitMongoDB(conf config.MongoConfig, log logger.Logger) *mongo.ConnectionMa
}
// Init Worker
func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger, notify notification.SDK, glmService *glm.SDK, minioService *minio.Service) {
func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger logger.Logger, notify notification.SDK, glmService *glm.SDK, minioService *minio.Service) *schedule.CronScheduler {
// Debug: Log worker config
appLogger.Info("Worker configuration", map[string]interface{}{
"worker_interval": config.Worker.Interval,
@@ -88,6 +88,9 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
noticeRepo := notice.NewRepository(mongoManager, appLogger)
tenderRepo := tender.NewRepository(mongoManager, appLogger)
// Create a single shared cron scheduler for all recurring jobs
scheduler := schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo)
// Initialize Notice Worker
appLogger.Info("Starting notice worker", map[string]interface{}{
"processing_limit": config.Worker.NoticeProcessingLimit,
@@ -130,7 +133,7 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
"interval": config.Queue.ProducerInterval,
})
schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{
scheduler.AddJob(schedule.Job{
Name: "Queue Producer Worker Job",
Func: func() {
producer := workers.NewQueueProducerWorker(
@@ -153,7 +156,7 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
summarizerWorker.Run()
// Schedule Document Summarization Worker job
schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{
scheduler.AddJob(schedule.Job{
Name: "Document Summarization Worker Job",
Func: func() {
worker := workers.NewDocumentSummarizationWorker(mongoManager, appLogger, tenderRepo, minioService, glmService)
@@ -174,7 +177,7 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
})
}
schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo).AddJob(schedule.Job{
scheduler.AddJob(schedule.Job{
Name: "Notice Worker Job",
Func: func() {
worker := workers.NewNoticeWorker(mongoManager, appLogger, &notify, noticeRepo, tenderRepo, glmService, config.Worker.NoticeProcessingLimit)
@@ -182,6 +185,12 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
},
Expr: workerInterval,
})
// Start the cron scheduler so all recurring jobs actually run
scheduler.Start()
appLogger.Info("Cron scheduler started with all worker jobs", map[string]interface{}{})
return scheduler
}
// Init Notification Service
+6 -1
View File
@@ -55,7 +55,7 @@ func main() {
}
// Initialize Worker
bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, glmService, minioService)
scheduler := bootstrap.InitWorker(*config, mongoManager, appLogger, notificationService, glmService, minioService)
// Set up signal handling for graceful shutdown
signalChan := make(chan os.Signal, 1)
@@ -65,5 +65,10 @@ func main() {
<-signalChan
appLogger.Info("Received shutdown signal, stopping scheduler...", map[string]interface{}{})
// Stop scheduler gracefully
if scheduler != nil {
scheduler.Stop()
}
appLogger.Info("Worker application stopped", map[string]interface{}{})
}
+3 -5
View File
@@ -39,9 +39,10 @@ func (w *DocumentSummarizationWorker) Run() {
w.Logger.Info("Document summarization worker started", map[string]interface{}{})
limit := 5 // Process fewer tenders at a time since summarization is resource-intensive
skip := 0
for {
tenders, totalCount, err := w.TenderRepo.GetUnSummarizedTenders(context.Background(), limit, skip)
// Always use skip=0 because processed items are excluded by the filter,
// so incrementing skip would cause unprocessed items to be skipped.
tenders, totalCount, err := w.TenderRepo.GetUnSummarizedTenders(context.Background(), limit, 0)
if err != nil {
w.Logger.Error("Failed to get un-summarized tenders", map[string]interface{}{
"error": err.Error(),
@@ -52,7 +53,6 @@ func (w *DocumentSummarizationWorker) Run() {
w.Logger.Info("Found tenders for document summarization", map[string]interface{}{
"count": len(tenders),
"total_count": totalCount,
"skip": skip,
})
if len(tenders) == 0 {
@@ -69,8 +69,6 @@ func (w *DocumentSummarizationWorker) Run() {
w.summarizeDocumentsForTender(&t)
}
skip += limit
}
w.Logger.Info("Document summarization worker completed", map[string]interface{}{})