Enhance notification delivery system with scheduled processing
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
- Introduced a new `NotificationWorker` to promote due scheduled notifications from pending to sent, improving notification management. - Added `NotificationInterval` configuration to schedule the notification delivery worker, with a default value for flexibility. - Implemented `MarkDueScheduledAsSent` method in the notification repository to update the status of notifications based on their delivery time. - Updated the notification service to process due scheduled notifications during relevant operations, ensuring timely delivery. This update enhances the notification system by automating the delivery of scheduled notifications, improving user engagement and operational efficiency.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
"tm/cmd/worker/workers"
|
||||
"tm/internal/notice"
|
||||
notificationDomain "tm/internal/notification"
|
||||
"tm/internal/tender"
|
||||
ai_summarizer "tm/pkg/ai_summarizer"
|
||||
"tm/pkg/config"
|
||||
@@ -87,10 +88,12 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
|
||||
"notice_fetch_error_backoff": config.Worker.NoticeFetchErrorBackoff.String(),
|
||||
"translation_enabled": config.Worker.TranslationEnabled,
|
||||
"translation_interval": config.Worker.TranslationInterval,
|
||||
"notification_interval": config.Worker.NotificationInterval,
|
||||
})
|
||||
// Initialize repositories
|
||||
noticeRepo := notice.NewRepository(mongoManager, appLogger)
|
||||
tenderRepo := tender.NewRepository(mongoManager, appLogger)
|
||||
notificationRepo := notificationDomain.NewRepository(mongoManager, appLogger)
|
||||
|
||||
// Create a single shared cron scheduler for all recurring jobs
|
||||
scheduler := schedule.NewCronScheduler(appLogger, mongoManager, noticeRepo)
|
||||
@@ -159,6 +162,26 @@ func InitWorker(config Config, mongoManager *mongo.ConnectionManager, appLogger
|
||||
appLogger.Warn("AI summarizer client not available, tender translation worker is disabled", map[string]interface{}{})
|
||||
}
|
||||
|
||||
notificationInterval := config.Worker.NotificationInterval
|
||||
if notificationInterval == "" {
|
||||
notificationInterval = "0 * * * * *"
|
||||
appLogger.Warn("WORKER_NOTIFICATION_INTERVAL not set, using default schedule", map[string]interface{}{
|
||||
"interval": notificationInterval,
|
||||
})
|
||||
}
|
||||
|
||||
scheduler.AddJob(schedule.Job{
|
||||
Name: "Scheduled Notification Worker Job",
|
||||
Func: func() {
|
||||
worker := workers.NewNotificationWorker(notificationRepo, appLogger)
|
||||
worker.Run()
|
||||
},
|
||||
Expr: notificationInterval,
|
||||
})
|
||||
appLogger.Info("Scheduled notification delivery worker", map[string]interface{}{
|
||||
"interval": notificationInterval,
|
||||
})
|
||||
|
||||
// Kick off one notice-processing pass without blocking startup (cron continues on schedule)
|
||||
go func() {
|
||||
w := workers.NewNoticeWorker(
|
||||
|
||||
Reference in New Issue
Block a user