service

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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

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

GetStats retrieves notification statistics.

func (*NotificationService) GetTemplate

GetTemplate retrieves a template by ID or name.

func (*NotificationService) ListNotifications

ListNotifications retrieves notifications with optional filters.

func (*NotificationService) ListTemplates

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

func (s *NotificationService) ReplayNotification(ctx context.Context, id string) *errors.Error

ReplayNotification re-queues a failed or delivered notification for testing.

func (*NotificationService) SendNotification

SendNotification creates and queues a notification for delivery.

func (*NotificationService) UpdateTemplate

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.

func (*TemplateEngine) Render

func (e *TemplateEngine) Render(template string, variables map[string]interface{}) (string, []string)

Render replaces all {{variable}} placeholders in the template with actual values. Returns the rendered text and a list of variables that were substituted.

func (*TemplateEngine) Validate

func (e *TemplateEngine) Validate(template string, variables map[string]interface{}) []string

Validate checks if all required variables are present in the provided variables map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL