Documentation
¶
Index ¶
- Constants
- type CampaignMessage
- type Config
- type DataSource
- type Manager
- func (m *Manager) AddMessenger(msg messenger.Messenger) error
- func (m *Manager) Close()
- func (m *Manager) HasMessenger(id string) bool
- func (m *Manager) HasRunningCampaigns() bool
- func (m *Manager) NewCampaignMessage(c *models.Campaign, s models.Subscriber) (CampaignMessage, error)
- func (m *Manager) PushCampaignMessage(msg CampaignMessage) error
- func (m *Manager) PushMessage(msg Message) error
- func (m *Manager) Run(tick time.Duration)
- func (m *Manager) TemplateFuncs(c *models.Campaign) template.FuncMap
- type Message
Constants ¶
const ( // BaseTPL is the name of the base template. BaseTPL = "base" // ContentTpl is the name of the compiled message. ContentTpl = "content" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CampaignMessage ¶
type CampaignMessage struct { Campaign *models.Campaign Subscriber models.Subscriber // contains filtered or unexported fields }
CampaignMessage represents an instance of campaign message to be pushed out, specific to a subscriber, via the campaign's messenger.
func (*CampaignMessage) AltBody ¶
func (m *CampaignMessage) AltBody() []byte
AltBody returns a copy of the message's alt body.
func (*CampaignMessage) Body ¶
func (m *CampaignMessage) Body() []byte
Body returns a copy of the message body.
func (*CampaignMessage) Subject ¶
func (m *CampaignMessage) Subject() string
Subject returns a copy of the message subject
type Config ¶
type Config struct { // Number of subscribers to pull from the DB in a single iteration. BatchSize int Concurrency int MessageRate int MaxSendErrors int SlidingWindow bool SlidingWindowDuration time.Duration SlidingWindowRate int RequeueOnError bool FromEmail string IndividualTracking bool LinkTrackURL string UnsubURL string OptinURL string MessageURL string ViewTrackURL string UnsubHeader bool }
Config has parameters for configuring the manager.
type DataSource ¶
type DataSource interface { NextCampaigns(excludeIDs []int64) ([]*models.Campaign, error) NextSubscribers(campID, limit int) ([]models.Subscriber, error) GetCampaign(campID int) (*models.Campaign, error) UpdateCampaignStatus(campID int, status string) error CreateLink(url string) (string, error) }
DataSource represents a data backend, such as a database, that provides subscriber and campaign records.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the scheduling, processing, and queuing of campaigns and message pushes.
func New ¶
func New(cfg Config, src DataSource, notifCB models.AdminNotifCallback, i *i18n.I18n, l *log.Logger) *Manager
New returns a new instance of Mailer.
func (*Manager) AddMessenger ¶
AddMessenger adds a Messenger messaging backend to the manager.
func (*Manager) HasMessenger ¶
HasMessenger checks if a given messenger is registered.
func (*Manager) HasRunningCampaigns ¶
HasRunningCampaigns checks if there are any active campaigns.
func (*Manager) NewCampaignMessage ¶
func (m *Manager) NewCampaignMessage(c *models.Campaign, s models.Subscriber) (CampaignMessage, error)
NewCampaignMessage creates and returns a CampaignMessage that is made available to message templates while they're compiled. It represents a message from a campaign that's bound to a single Subscriber.
func (*Manager) PushCampaignMessage ¶ added in v1.1.0
func (m *Manager) PushCampaignMessage(msg CampaignMessage) error
PushCampaignMessage pushes a campaign messages to be sent out by the workers. It times out if the queue is busy.
func (*Manager) PushMessage ¶
PushMessage pushes an arbitrary non-campaign Message to be sent out by the workers. It times out if the queue is busy.
func (*Manager) Run ¶
Run is a blocking function (that should be invoked as a goroutine) that scans the data source at regular intervals for pending campaigns, and queues them for processing. The process queue fetches batches of subscribers and pushes messages to them for each queued campaign until all subscribers are exhausted, at which point, a campaign is marked as "finished".