Documentation
¶
Overview ¶
Package reminder provides reminder management for schedules and todos.
Package reminder provides reminder management for schedules and todos.
Package reminder provides reminder management for schedules and todos.
Package reminder provides reminder management for schedules and todos.
Index ¶
- type AppNotification
- type AppNotificationSender
- type AppNotificationStore
- type Channel
- type ChannelSender
- type CreateReminderRequest
- type EmailConfig
- type EmailSender
- type HabitAnalyzer
- type HealthCheck
- type HealthStatus
- type Integrator
- func (i *Integrator) BatchCreateForSchedules(ctx context.Context, userID int32, schedules []*ScheduleInfo) ([]*Reminder, error)
- func (i *Integrator) CreateSmartReminder(ctx context.Context, userID int32, suggestion SmartSuggestion) (*Reminder, error)
- func (i *Integrator) GetUpcomingReminders(ctx context.Context, userID int32) ([]*Reminder, error)
- func (i *Integrator) OnScheduleCreated(ctx context.Context, userID int32, schedule *ScheduleInfo) (*Reminder, error)
- func (i *Integrator) OnScheduleDeleted(ctx context.Context, scheduleID string) error
- func (i *Integrator) OnScheduleUpdated(ctx context.Context, userID int32, schedule *ScheduleInfo) (*Reminder, error)
- func (i *Integrator) OnTodoCompleted(ctx context.Context, todoID string) error
- func (i *Integrator) OnTodoCreated(ctx context.Context, userID int32, todo *TodoInfo) (*Reminder, error)
- func (i *Integrator) OnTodoDeleted(ctx context.Context, todoID string) error
- func (i *Integrator) OnTodoUpdated(ctx context.Context, userID int32, todo *TodoInfo) (*Reminder, error)
- func (i *Integrator) SyncScheduleReminders(ctx context.Context, userID int32, schedules []*ScheduleInfo) error
- type MemoryAppNotificationStore
- type MemoryStore
- func (s *MemoryStore) Create(ctx context.Context, reminder *Reminder) error
- func (s *MemoryStore) Delete(ctx context.Context, id string) error
- func (s *MemoryStore) Get(ctx context.Context, id string) (*Reminder, error)
- func (s *MemoryStore) GetByTarget(ctx context.Context, targetID string) ([]*Reminder, error)
- func (s *MemoryStore) GetByUser(ctx context.Context, userID int32, status ReminderStatus) ([]*Reminder, error)
- func (s *MemoryStore) GetDueReminders(ctx context.Context, before time.Time) ([]*Reminder, error)
- func (s *MemoryStore) MarkFailed(ctx context.Context, id string, reason string) error
- func (s *MemoryStore) MarkSent(ctx context.Context, id string) error
- func (s *MemoryStore) Update(ctx context.Context, reminder *Reminder) error
- type MetricsCollector
- type MockEmailResolver
- type MockNotifier
- type NotificationDispatcher
- func (d *NotificationDispatcher) Broadcast(ctx context.Context, userID int32, message string) []error
- func (d *NotificationDispatcher) Register(channel Channel, sender ChannelSender)
- func (d *NotificationDispatcher) Send(ctx context.Context, userID int32, channel Channel, message string) error
- func (d *NotificationDispatcher) SendWithMetadata(ctx context.Context, userID int32, channel Channel, message string, ...) error
- type Notifier
- type Reminder
- type ReminderStatus
- type ReminderStore
- type ReminderType
- type ScheduleInfo
- type Scheduler
- type SchedulerConfig
- type SentMessage
- type Service
- func (s *Service) Cancel(ctx context.Context, id string) error
- func (s *Service) CancelByTarget(ctx context.Context, targetID string) error
- func (s *Service) CreateCustom(ctx context.Context, req *CreateReminderRequest) (*Reminder, error)
- func (s *Service) CreateForSchedule(ctx context.Context, userID int32, schedule *ScheduleInfo, leadMinutes int) (*Reminder, error)
- func (s *Service) GetReminder(ctx context.Context, id string) (*Reminder, error)
- func (s *Service) GetUserReminders(ctx context.Context, userID int32, status ReminderStatus) ([]*Reminder, error)
- func (s *Service) ProcessDueReminders(ctx context.Context) (int, error)
- func (s *Service) SetDefaultChannels(channels []Channel)
- func (s *Service) SetDefaultLeadTime(minutes int)
- type SmartSuggestion
- type Stats
- type TodoInfo
- type UserEmailResolver
- type WebhookConfig
- type WebhookPayload
- type WebhookSender
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppNotification ¶
type AppNotification struct {
ID string `json:"id"`
UserID int32 `json:"user_id"`
Type string `json:"type"`
Title string `json:"title"`
Message string `json:"message"`
Read bool `json:"read"`
CreatedAt time.Time `json:"created_at"`
Metadata map[string]any `json:"metadata,omitempty"`
}
AppNotification represents an in-app notification.
type AppNotificationSender ¶
type AppNotificationSender struct {
// contains filtered or unexported fields
}
AppNotificationSender sends in-app notifications.
func NewAppNotificationSender ¶
func NewAppNotificationSender(store AppNotificationStore) *AppNotificationSender
NewAppNotificationSender creates a new app notification sender.
func (*AppNotificationSender) Name ¶
func (s *AppNotificationSender) Name() string
Name returns the sender name.
type AppNotificationStore ¶
type AppNotificationStore interface {
CreateNotification(ctx context.Context, notification *AppNotification) error
}
AppNotificationStore defines storage for in-app notifications.
type ChannelSender ¶
type ChannelSender interface {
Send(ctx context.Context, userID int32, message string, metadata map[string]any) error
Name() string
}
ChannelSender defines the interface for sending notifications.
type CreateReminderRequest ¶
type CreateReminderRequest struct {
UserID int32
Type ReminderType
TargetID string
TriggerAt time.Time
Message string
Channels []Channel
LeadMinutes int // Minutes before event to trigger
}
CreateReminderRequest represents a request to create a reminder.
type EmailConfig ¶
type EmailConfig struct {
SMTPHost string
SMTPPort int
Username string
Password string
FromAddress string
FromName string
TemplateHTML string
}
EmailConfig holds email configuration.
type EmailSender ¶
type EmailSender struct {
// contains filtered or unexported fields
}
EmailSender sends email notifications.
func NewEmailSender ¶
func NewEmailSender(config EmailConfig, resolver UserEmailResolver) *EmailSender
NewEmailSender creates a new email sender.
type HabitAnalyzer ¶
type HabitAnalyzer interface {
GetUserHabits(ctx context.Context, userID int32) (*habit.UserHabits, error)
}
HabitAnalyzer provides user habit analysis.
type HealthCheck ¶
type HealthCheck struct {
// contains filtered or unexported fields
}
HealthCheck provides health check for the scheduler.
func NewHealthCheck ¶
func NewHealthCheck(scheduler *Scheduler) *HealthCheck
NewHealthCheck creates a new health check for the scheduler.
func (*HealthCheck) Check ¶
func (h *HealthCheck) Check() HealthStatus
Check returns the health status.
type HealthStatus ¶
type HealthStatus struct {
Healthy bool `json:"healthy"`
LastCheck time.Time `json:"last_check"`
CheckCount int64 `json:"check_count"`
}
HealthStatus represents the health of the scheduler.
type Integrator ¶
type Integrator struct {
// contains filtered or unexported fields
}
Integrator provides integration between reminders and other entities.
func NewIntegrator ¶
func NewIntegrator(service *Service, habitAnalyzer HabitAnalyzer) *Integrator
NewIntegrator creates a new reminder integrator.
func (*Integrator) BatchCreateForSchedules ¶
func (i *Integrator) BatchCreateForSchedules(ctx context.Context, userID int32, schedules []*ScheduleInfo) ([]*Reminder, error)
BatchCreateForSchedules creates reminders for multiple schedules.
func (*Integrator) CreateSmartReminder ¶
func (i *Integrator) CreateSmartReminder(ctx context.Context, userID int32, suggestion SmartSuggestion) (*Reminder, error)
CreateSmartReminder creates an AI-suggested reminder based on context.
func (*Integrator) GetUpcomingReminders ¶
GetUpcomingReminders gets all upcoming reminders for a user.
func (*Integrator) OnScheduleCreated ¶
func (i *Integrator) OnScheduleCreated(ctx context.Context, userID int32, schedule *ScheduleInfo) (*Reminder, error)
OnScheduleCreated handles schedule creation event.
func (*Integrator) OnScheduleDeleted ¶
func (i *Integrator) OnScheduleDeleted(ctx context.Context, scheduleID string) error
OnScheduleDeleted handles schedule deletion event.
func (*Integrator) OnScheduleUpdated ¶
func (i *Integrator) OnScheduleUpdated(ctx context.Context, userID int32, schedule *ScheduleInfo) (*Reminder, error)
OnScheduleUpdated handles schedule update event.
func (*Integrator) OnTodoCompleted ¶
func (i *Integrator) OnTodoCompleted(ctx context.Context, todoID string) error
OnTodoCompleted handles todo completion event.
func (*Integrator) OnTodoCreated ¶
func (i *Integrator) OnTodoCreated(ctx context.Context, userID int32, todo *TodoInfo) (*Reminder, error)
OnTodoCreated handles todo creation event.
func (*Integrator) OnTodoDeleted ¶
func (i *Integrator) OnTodoDeleted(ctx context.Context, todoID string) error
OnTodoDeleted handles todo deletion event.
func (*Integrator) OnTodoUpdated ¶
func (i *Integrator) OnTodoUpdated(ctx context.Context, userID int32, todo *TodoInfo) (*Reminder, error)
OnTodoUpdated handles todo update event.
func (*Integrator) SyncScheduleReminders ¶
func (i *Integrator) SyncScheduleReminders(ctx context.Context, userID int32, schedules []*ScheduleInfo) error
SyncScheduleReminders syncs reminders with schedule changes.
type MemoryAppNotificationStore ¶
type MemoryAppNotificationStore struct {
// contains filtered or unexported fields
}
MemoryAppNotificationStore is an in-memory implementation for testing.
func NewMemoryAppNotificationStore ¶
func NewMemoryAppNotificationStore() *MemoryAppNotificationStore
NewMemoryAppNotificationStore creates a new in-memory notification store.
func (*MemoryAppNotificationStore) CreateNotification ¶
func (s *MemoryAppNotificationStore) CreateNotification(ctx context.Context, notification *AppNotification) error
CreateNotification stores a notification.
func (*MemoryAppNotificationStore) GetAll ¶
func (s *MemoryAppNotificationStore) GetAll() []*AppNotification
GetAll returns all notifications (for testing).
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory implementation of ReminderStore for testing.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory reminder store.
func (*MemoryStore) Create ¶
func (s *MemoryStore) Create(ctx context.Context, reminder *Reminder) error
Create stores a new reminder.
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(ctx context.Context, id string) error
Delete removes a reminder.
func (*MemoryStore) GetByTarget ¶
GetByTarget retrieves all reminders for a target.
func (*MemoryStore) GetByUser ¶
func (s *MemoryStore) GetByUser(ctx context.Context, userID int32, status ReminderStatus) ([]*Reminder, error)
GetByUser retrieves all reminders for a user with optional status filter.
func (*MemoryStore) GetDueReminders ¶
GetDueReminders retrieves all pending reminders due before the given time.
func (*MemoryStore) MarkFailed ¶
MarkFailed marks a reminder as failed.
type MetricsCollector ¶
type MetricsCollector struct {
// contains filtered or unexported fields
}
MetricsCollector collects scheduler metrics.
func NewMetricsCollector ¶
func NewMetricsCollector() *MetricsCollector
NewMetricsCollector creates a new metrics collector.
func (*MetricsCollector) GetStats ¶
func (m *MetricsCollector) GetStats() Stats
GetStats returns current statistics.
func (*MetricsCollector) RecordFailed ¶
func (m *MetricsCollector) RecordFailed(count int)
RecordFailed records failed reminders.
func (*MetricsCollector) RecordProcessed ¶
func (m *MetricsCollector) RecordProcessed(count int)
RecordProcessed records processed reminders.
type MockEmailResolver ¶
type MockEmailResolver struct {
// contains filtered or unexported fields
}
MockEmailResolver is a mock implementation of UserEmailResolver.
func NewMockEmailResolver ¶
func NewMockEmailResolver() *MockEmailResolver
NewMockEmailResolver creates a new mock email resolver.
func (*MockEmailResolver) SetEmail ¶
func (r *MockEmailResolver) SetEmail(userID int32, email string)
SetEmail sets an email for a user.
type MockNotifier ¶
type MockNotifier struct {
SentMessages []SentMessage
ShouldFail bool
// contains filtered or unexported fields
}
MockNotifier is a mock implementation of Notifier for testing.
func NewMockNotifier ¶
func NewMockNotifier() *MockNotifier
NewMockNotifier creates a new mock notifier.
func (*MockNotifier) GetSentCount ¶
func (n *MockNotifier) GetSentCount() int
GetSentCount returns the number of messages sent.
type NotificationDispatcher ¶
type NotificationDispatcher struct {
// contains filtered or unexported fields
}
NotificationDispatcher routes notifications to appropriate channels.
func NewNotificationDispatcher ¶
func NewNotificationDispatcher() *NotificationDispatcher
NewNotificationDispatcher creates a new notification dispatcher.
func (*NotificationDispatcher) Broadcast ¶
func (d *NotificationDispatcher) Broadcast(ctx context.Context, userID int32, message string) []error
Broadcast sends a notification through all registered channels.
func (*NotificationDispatcher) Register ¶
func (d *NotificationDispatcher) Register(channel Channel, sender ChannelSender)
Register registers a channel sender.
type Notifier ¶
type Notifier interface {
Send(ctx context.Context, userID int32, channel Channel, message string) error
}
Notifier defines the notification interface.
type Reminder ¶
type Reminder struct {
ID string `json:"id"`
UserID int32 `json:"user_id"`
Type ReminderType `json:"type"`
TargetID string `json:"target_id"` // Schedule or Todo ID
TriggerAt time.Time `json:"trigger_at"`
Message string `json:"message"`
Channels []Channel `json:"channels"`
Status ReminderStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
SentAt *time.Time `json:"sent_at,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
Reminder represents a reminder entity.
type ReminderStatus ¶
type ReminderStatus string
ReminderStatus defines the status of a reminder.
const ( StatusPending ReminderStatus = "pending" StatusSent ReminderStatus = "sent" StatusCancelled ReminderStatus = "cancelled" StatusFailed ReminderStatus = "failed" )
type ReminderStore ¶
type ReminderStore interface {
Create(ctx context.Context, reminder *Reminder) error
Get(ctx context.Context, id string) (*Reminder, error)
GetByTarget(ctx context.Context, targetID string) ([]*Reminder, error)
GetDueReminders(ctx context.Context, before time.Time) ([]*Reminder, error)
GetByUser(ctx context.Context, userID int32, status ReminderStatus) ([]*Reminder, error)
Update(ctx context.Context, reminder *Reminder) error
Delete(ctx context.Context, id string) error
MarkSent(ctx context.Context, id string) error
MarkFailed(ctx context.Context, id string, reason string) error
}
ReminderStore defines the storage interface for reminders.
type ReminderType ¶
type ReminderType string
ReminderType defines the type of reminder.
const ( ReminderTypeSchedule ReminderType = "schedule" ReminderTypeTodo ReminderType = "todo" ReminderTypeSmart ReminderType = "smart" )
type ScheduleInfo ¶
ScheduleInfo contains schedule information for reminder creation.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs background tasks for processing due reminders.
func NewScheduler ¶
func NewScheduler(service *Service, config SchedulerConfig) *Scheduler
NewScheduler creates a new reminder scheduler.
func (*Scheduler) EnableTestMode ¶
EnableTestMode enables test mode with a channel for processed counts.
type SchedulerConfig ¶
type SchedulerConfig struct {
Interval time.Duration // How often to check for due reminders
MaxRetries int // Max retries for failed reminders
RetryDelay time.Duration // Delay between retries
BatchSize int // Max reminders to process per cycle
}
SchedulerConfig holds configuration for the scheduler.
func DefaultSchedulerConfig ¶
func DefaultSchedulerConfig() SchedulerConfig
DefaultSchedulerConfig returns default scheduler configuration.
type SentMessage ¶
SentMessage represents a message that was sent.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides reminder management functionality.
func NewService ¶
func NewService(store ReminderStore, notifier Notifier) *Service
NewService creates a new reminder service.
func (*Service) CancelByTarget ¶
CancelByTarget cancels all pending reminders for a target.
func (*Service) CreateCustom ¶
CreateCustom creates a custom reminder.
func (*Service) CreateForSchedule ¶
func (s *Service) CreateForSchedule(ctx context.Context, userID int32, schedule *ScheduleInfo, leadMinutes int) (*Reminder, error)
CreateForSchedule creates a reminder for a schedule.
func (*Service) GetReminder ¶
GetReminder gets a specific reminder.
func (*Service) GetUserReminders ¶
func (s *Service) GetUserReminders(ctx context.Context, userID int32, status ReminderStatus) ([]*Reminder, error)
GetUserReminders gets all reminders for a user.
func (*Service) ProcessDueReminders ¶
ProcessDueReminders processes all reminders that are due.
func (*Service) SetDefaultChannels ¶
SetDefaultChannels sets the default notification channels.
func (*Service) SetDefaultLeadTime ¶
SetDefaultLeadTime sets the default lead time for reminders.
type SmartSuggestion ¶
type SmartSuggestion struct {
RelatedEntityID string
SuggestedTime time.Time
Message string
Confidence float64
Reason string
}
SmartSuggestion represents an AI-generated reminder suggestion.
type Stats ¶
type Stats struct {
TotalProcessed int64 `json:"total_processed"`
TotalFailed int64 `json:"total_failed"`
LastRunAt time.Time `json:"last_run_at"`
AverageLatency float64 `json:"average_latency_ms"`
}
Stats holds scheduler statistics.
type TodoInfo ¶
type TodoInfo struct {
ID string
Title string
DueTime *time.Time
Priority string // high, medium, low
}
TodoInfo contains todo information for reminder creation.
type UserEmailResolver ¶
UserEmailResolver resolves user ID to email address.
type WebhookConfig ¶
type WebhookConfig struct {
URL string
Secret string
Timeout time.Duration
RetryAttempts int
Headers map[string]string
}
WebhookConfig holds webhook configuration.
type WebhookPayload ¶
type WebhookPayload struct {
Event string `json:"event"`
UserID int32 `json:"user_id"`
Message string `json:"message"`
Timestamp time.Time `json:"timestamp"`
Metadata map[string]any `json:"metadata,omitempty"`
}
WebhookPayload represents the webhook request body.
type WebhookSender ¶
type WebhookSender struct {
// contains filtered or unexported fields
}
WebhookSender sends webhook notifications.
func NewWebhookSender ¶
func NewWebhookSender(config WebhookConfig) *WebhookSender
NewWebhookSender creates a new webhook sender.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker handles reminder processing with retry logic.
func NewWorker ¶
func NewWorker(store ReminderStore, notifier Notifier, maxRetries int) *Worker
NewWorker creates a new reminder worker.