Enhance notification delivery system with scheduled processing
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:
Mazyar
2026-06-22 12:53:22 +03:30
parent db14bfe270
commit d486a5e44f
5 changed files with 122 additions and 0 deletions
+21
View File
@@ -5,6 +5,7 @@ import (
"errors"
"slices"
"strings"
"time"
"tm/internal/customer"
"tm/internal/user"
@@ -186,6 +187,8 @@ func (s *notificationService) persistNotification(ctx context.Context, recipient
}
func (s *notificationService) GetNotifications(ctx context.Context, req *SearchForm, pagination *response.Pagination) (*NotificationListResponse, error) {
s.processDueScheduled(ctx)
search := req.ResolvedSearch()
s.logger.Info("Getting notifications", map[string]interface{}{
@@ -264,6 +267,8 @@ func (s *notificationService) GetNotifications(ctx context.Context, req *SearchF
}
func (s *notificationService) GetNotification(ctx context.Context, notificationID string) (*NotificationResponse, error) {
s.processDueScheduled(ctx)
s.logger.Info("Getting notification", map[string]interface{}{
"notification_id": notificationID,
})
@@ -467,3 +472,19 @@ func (s *notificationService) getCustomers(ctx context.Context, values []string,
return recipients, nil
}
func (s *notificationService) processDueScheduled(ctx context.Context) {
count, err := s.repository.MarkDueScheduledAsSent(ctx, time.Now().Unix())
if err != nil {
s.logger.Error("Failed to process due scheduled notifications", map[string]interface{}{
"error": err.Error(),
})
return
}
if count > 0 {
s.logger.Info("Processed due scheduled notifications", map[string]interface{}{
"count": count,
})
}
}