Documentation
¶
Index ¶
- type NotificationRepositoryInterface
- type NotificationService
- func (s *NotificationService) CreateTemplate(ctx context.Context, req *models.CreateTemplateRequest) (*models.NotificationTemplate, *errors.Error)
- func (s *NotificationService) GetNotification(ctx context.Context, id string) (*models.Notification, *errors.Error)
- func (s *NotificationService) GetStats(ctx context.Context) (*models.NotificationStats, *errors.Error)
- func (s *NotificationService) GetTemplate(ctx context.Context, id string) (*models.NotificationTemplate, *errors.Error)
- func (s *NotificationService) ListNotifications(ctx context.Context, req *models.ListNotificationsRequest) (*models.ListNotificationsResponse, *errors.Error)
- func (s *NotificationService) ListTemplates(ctx context.Context, channel *models.NotificationChannel) ([]*models.NotificationTemplate, *errors.Error)
- func (s *NotificationService) PreviewTemplate(ctx context.Context, templateID string, variables map[string]interface{}) (*models.PreviewTemplateResponse, *errors.Error)
- func (s *NotificationService) ProcessQueuedNotifications(ctx context.Context, batchSize int) *errors.Error
- func (s *NotificationService) ReplayNotification(ctx context.Context, id string) *errors.Error
- func (s *NotificationService) SendNotification(ctx context.Context, req *models.SendNotificationRequest) (*models.SendNotificationResponse, *errors.Error)
- func (s *NotificationService) UpdateTemplate(ctx context.Context, id string, req *models.UpdateTemplateRequest) *errors.Error
- type SimulationConfig
- type SimulationEngine
- type TemplateEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NotificationRepositoryInterface ¶
type NotificationRepositoryInterface interface {
UpdateStatus(ctx context.Context, id string, status models.NotificationStatus, failureReason *string) *errors.Error
IncrementRetryCount(ctx context.Context, id string) *errors.Error
GetQueuedNotifications(ctx context.Context, limit int) ([]*models.Notification, *errors.Error)
}
NotificationRepositoryInterface defines the repository methods needed by the simulation engine.
type NotificationService ¶
type NotificationService struct {
// contains filtered or unexported fields
}
NotificationService handles notification business logic.
func NewNotificationService ¶
func NewNotificationService( notifRepo *repository.NotificationRepository, templateRepo *repository.TemplateRepository, simConfig SimulationConfig, ) *NotificationService
NewNotificationService creates a new notification service.
func (*NotificationService) CreateTemplate ¶
func (s *NotificationService) CreateTemplate(ctx context.Context, req *models.CreateTemplateRequest) (*models.NotificationTemplate, *errors.Error)
CreateTemplate creates a new notification template.
func (*NotificationService) GetNotification ¶
func (s *NotificationService) GetNotification(ctx context.Context, id string) (*models.Notification, *errors.Error)
GetNotification retrieves a notification by ID.
func (*NotificationService) GetStats ¶
func (s *NotificationService) GetStats(ctx context.Context) (*models.NotificationStats, *errors.Error)
GetStats retrieves notification statistics.
func (*NotificationService) GetTemplate ¶
func (s *NotificationService) GetTemplate(ctx context.Context, id string) (*models.NotificationTemplate, *errors.Error)
GetTemplate retrieves a template by ID or name.
func (*NotificationService) ListNotifications ¶
func (s *NotificationService) ListNotifications(ctx context.Context, req *models.ListNotificationsRequest) (*models.ListNotificationsResponse, *errors.Error)
ListNotifications retrieves notifications with optional filters.
func (*NotificationService) ListTemplates ¶
func (s *NotificationService) ListTemplates(ctx context.Context, channel *models.NotificationChannel) ([]*models.NotificationTemplate, *errors.Error)
ListTemplates retrieves all templates, optionally filtered by channel.
func (*NotificationService) PreviewTemplate ¶
func (s *NotificationService) PreviewTemplate(ctx context.Context, templateID string, variables map[string]interface{}) (*models.PreviewTemplateResponse, *errors.Error)
PreviewTemplate renders a template with provided variables (for testing).
func (*NotificationService) ProcessQueuedNotifications ¶
func (s *NotificationService) ProcessQueuedNotifications(ctx context.Context, batchSize int) *errors.Error
ProcessQueuedNotifications processes queued notifications (called by background worker).
func (*NotificationService) ReplayNotification ¶
ReplayNotification re-queues a failed or delivered notification for testing.
func (*NotificationService) SendNotification ¶
func (s *NotificationService) SendNotification(ctx context.Context, req *models.SendNotificationRequest) (*models.SendNotificationResponse, *errors.Error)
SendNotification creates and queues a notification for delivery.
func (*NotificationService) UpdateTemplate ¶
func (s *NotificationService) UpdateTemplate(ctx context.Context, id string, req *models.UpdateTemplateRequest) *errors.Error
UpdateTemplate updates an existing template.
type SimulationConfig ¶
type SimulationConfig struct {
DeliveryDelayMs int // Delay in milliseconds before marking as sent
FinalDelayMs int // Delay in milliseconds before final status (delivered/failed)
FailureRatePercent float64 // Percentage of notifications that should fail (0-100)
MaxRetryAttempts int // Maximum retry attempts for failed notifications
RetryDelayMs int // Base delay between retries (exponential backoff)
CriticalPriorityOnly bool // Process only critical priority (for testing)
}
SimulationConfig holds configuration for the notification simulation engine.
func DefaultSimulationConfig ¶
func DefaultSimulationConfig() SimulationConfig
DefaultSimulationConfig returns sensible defaults for simulation.
type SimulationEngine ¶
type SimulationEngine struct {
// contains filtered or unexported fields
}
SimulationEngine simulates notification delivery with realistic behavior.
func NewSimulationEngine ¶
func NewSimulationEngine(config SimulationConfig, repo NotificationRepositoryInterface) *SimulationEngine
NewSimulationEngine creates a new simulation engine.
func (*SimulationEngine) CalculateRetryDelay ¶
func (e *SimulationEngine) CalculateRetryDelay(retryCount int) time.Duration
CalculateRetryDelay calculates the delay before next retry using exponential backoff.
func (*SimulationEngine) GetProcessingDelay ¶
func (e *SimulationEngine) GetProcessingDelay() time.Duration
GetProcessingDelay returns the total processing delay for a notification.
func (*SimulationEngine) ProcessNotification ¶
func (e *SimulationEngine) ProcessNotification(ctx context.Context, notif *models.Notification) *errors.Error
ProcessNotification simulates processing a single notification. This is the core simulation logic that mimics real-world delivery.
type TemplateEngine ¶
type TemplateEngine struct {
// contains filtered or unexported fields
}
TemplateEngine handles variable substitution in notification templates.
func NewTemplateEngine ¶
func NewTemplateEngine() *TemplateEngine
NewTemplateEngine creates a new template engine.
func (*TemplateEngine) ExtractVariables ¶
func (e *TemplateEngine) ExtractVariables(template string) []string
ExtractVariables extracts all variable names from a template.