Documentation
¶
Index ¶
- Constants
- func JobInsertOptions() *river.InsertOpts
- func JobInsertOptionsWithQueue(queue string) *river.InsertOpts
- func JobInsertOptionsWithRetry(queue string, maxAttempts int) *river.InsertOpts
- func NewDigestPeriodicJob(cronSchedule string, logger *zap.SugaredLogger) *river.PeriodicJob
- func Workers(emailService EmailService, digestService DigestService, logger Logger) *river.Workers
- type DigestService
- type EmailService
- type Logger
- type SendEmailArgs
- type SendEmailFromArgs
- type SendEmailFromWorker
- type SendEmailWorker
- type SendGlobalDigestArgs
- type SendGlobalDigestWorker
- type Service
- func (s *Service) EnqueueSendEmail(ctx context.Context, args *SendEmailArgs) error
- func (s *Service) EnqueueSendEmailFrom(ctx context.Context, args *SendEmailFromArgs) error
- func (s *Service) GetClient() *river.Client[pgx.Tx]
- func (s *Service) IsStarted() bool
- func (s *Service) Migrate(ctx context.Context) error
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop(ctx context.Context) error
Constants ¶
const ( JobTypeSendEmail = "send_email" JobTypeSendEmailFrom = "send_email_from" JobTypeSendGlobalDigest = "send_global_digest" )
Job types for email processing
Variables ¶
This section is empty.
Functions ¶
func JobInsertOptions ¶
func JobInsertOptions() *river.InsertOpts
JobInsertOptions returns common insert options for email jobs
func JobInsertOptionsWithQueue ¶
func JobInsertOptionsWithQueue(queue string) *river.InsertOpts
JobInsertOptionsWithQueue returns insert options for jobs with specified queue
func JobInsertOptionsWithRetry ¶
func JobInsertOptionsWithRetry(queue string, maxAttempts int) *river.InsertOpts
JobInsertOptionsWithRetry returns insert options for jobs with custom retry policy
func NewDigestPeriodicJob ¶
func NewDigestPeriodicJob(cronSchedule string, logger *zap.SugaredLogger) *river.PeriodicJob
NewDigestPeriodicJob creates a periodic job for digest scheduling
func Workers ¶
func Workers(emailService EmailService, digestService DigestService, logger Logger) *river.Workers
Workers returns all workers as work functions with dependencies injected
Types ¶
type DigestService ¶
DigestService interface for dependency injection
type EmailService ¶
type EmailService interface {
Send(ctx context.Context, message *types.Message) (*types.SendResult, error)
SendWithProvider(ctx context.Context, providerName string, message *types.Message) (*types.SendResult, error)
}
EmailService interface for dependency injection
type Logger ¶
type Logger interface {
Infow(msg string, keysAndValues ...interface{})
Errorw(msg string, keysAndValues ...interface{})
Warnw(msg string, keysAndValues ...interface{})
Debugw(msg string, keysAndValues ...interface{})
}
Logger interface for logging
type SendEmailArgs ¶
type SendEmailArgs struct {
// Email message fields
From string `json:"from"`
To []string `json:"to"`
Cc []string `json:"cc,omitempty"`
Bcc []string `json:"bcc,omitempty"`
Subject string `json:"subject"`
HTMLBody string `json:"html_body,omitempty"`
TextBody string `json:"text_body,omitempty"`
Attachments []types.Attachment `json:"attachments,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
SendEmailArgs represents the arguments for sending an email
func (SendEmailArgs) Timeout ¶
func (SendEmailArgs) Timeout() time.Duration
Timeout returns the timeout for email jobs
type SendEmailFromArgs ¶
type SendEmailFromArgs struct {
// Provider to use for sending
Provider string `json:"provider"`
// Email message fields
From string `json:"from"`
To []string `json:"to"`
Cc []string `json:"cc,omitempty"`
Bcc []string `json:"bcc,omitempty"`
Subject string `json:"subject"`
HTMLBody string `json:"html_body,omitempty"`
TextBody string `json:"text_body,omitempty"`
Attachments []types.Attachment `json:"attachments,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
SendEmailFromArgs represents the arguments for sending an email from a specific provider
func (SendEmailFromArgs) Kind ¶
func (SendEmailFromArgs) Kind() string
Kind returns the job kind for River
func (SendEmailFromArgs) Timeout ¶
func (SendEmailFromArgs) Timeout() time.Duration
Timeout returns the timeout for email jobs
type SendEmailFromWorker ¶
type SendEmailFromWorker struct {
// contains filtered or unexported fields
}
SendEmailFromWorker handles sending email from provider jobs
func NewSendEmailFromWorker ¶
func NewSendEmailFromWorker(emailService EmailService, logger Logger) *SendEmailFromWorker
NewSendEmailFromWorker creates a new SendEmailFromWorker
func (*SendEmailFromWorker) Work ¶
func (w *SendEmailFromWorker) Work(ctx context.Context, job *river.Job[SendEmailFromArgs]) error
Work is the River work function for sending emails from a provider
type SendEmailWorker ¶
type SendEmailWorker struct {
// contains filtered or unexported fields
}
SendEmailWorker handles sending email jobs
func NewSendEmailWorker ¶
func NewSendEmailWorker(emailService EmailService, logger Logger) *SendEmailWorker
NewSendEmailWorker creates a new SendEmailWorker
func (*SendEmailWorker) Work ¶
func (w *SendEmailWorker) Work(ctx context.Context, job *river.Job[SendEmailArgs]) error
Work is the River work function for sending emails
type SendGlobalDigestArgs ¶
type SendGlobalDigestArgs struct {
}
SendGlobalDigestArgs represents the arguments for sending global digest
func (SendGlobalDigestArgs) Kind ¶
func (SendGlobalDigestArgs) Kind() string
Kind returns the job kind for River
func (SendGlobalDigestArgs) Timeout ¶
func (SendGlobalDigestArgs) Timeout() time.Duration
Timeout returns the timeout for digest jobs (longer due to multiple emails)
type SendGlobalDigestWorker ¶
type SendGlobalDigestWorker struct {
// contains filtered or unexported fields
}
SendGlobalDigestWorker handles sending global digest jobs
func NewSendGlobalDigestWorker ¶
func NewSendGlobalDigestWorker(digestService DigestService, logger Logger) *SendGlobalDigestWorker
NewSendGlobalDigestWorker creates a new SendGlobalDigestWorker
func (*SendGlobalDigestWorker) Work ¶
func (w *SendGlobalDigestWorker) Work(ctx context.Context, job *river.Job[SendGlobalDigestArgs]) error
Work is the River work function for sending global digest
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages the River client and workers
func NewService ¶
func NewService( cfg *config.WorkerConfig, db *gorm.DB, emailSvc *email.Service, logger *zap.SugaredLogger, ) (*Service, error)
NewService creates a new worker service
func NewServiceWithDigest ¶
func NewServiceWithDigest( cfg *config.WorkerConfig, db *gorm.DB, emailSvc *email.Service, digestSvc DigestService, digestCfg *config.Config, logger *zap.SugaredLogger, ) (*Service, error)
NewServiceWithDigest creates a new worker service with digest support
func (*Service) EnqueueSendEmail ¶
func (s *Service) EnqueueSendEmail(ctx context.Context, args *SendEmailArgs) error
EnqueueSendEmail enqueues a send email job
func (*Service) EnqueueSendEmailFrom ¶
func (s *Service) EnqueueSendEmailFrom(ctx context.Context, args *SendEmailFromArgs) error
EnqueueSendEmailFrom enqueues a send email from provider job