Documentation ¶
Index ¶
- Constants
- type CampaignMessage
- type Config
- type DataSource
- type Manager
- func (m *Manager) AddMessenger(msg messenger.Messenger) error
- func (m *Manager) GetMessengerNames() []string
- func (m *Manager) HasMessenger(id string) bool
- func (m *Manager) NewCampaignMessage(c *models.Campaign, s models.Subscriber) CampaignMessage
- func (m *Manager) PushMessage(msg Message) error
- func (m *Manager) Run(tick time.Duration)
- func (m *Manager) SpawnWorkers()
- 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) Body ¶
func (m *CampaignMessage) Body() []byte
Body returns a copy of the message body.
func (*CampaignMessage) Render ¶
func (m *CampaignMessage) Render() error
Render takes a Message, executes its pre-compiled Campaign.Tpl and applies the resultant bytes to Message.body to be used in messages.
type Config ¶
type Config struct { Concurrency int MaxSendErrors int RequeueOnError bool FromEmail string LinkTrackURL string UnsubURL string OptinURL string ViewTrackURL string }
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, 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) GetMessengerNames ¶
GetMessengerNames returns the list of registered messengers.
func (*Manager) HasMessenger ¶
HasMessenger checks if a given messenger is registered.
func (*Manager) NewCampaignMessage ¶
func (m *Manager) NewCampaignMessage(c *models.Campaign, s models.Subscriber) CampaignMessage
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) PushMessage ¶
PushMessage pushes a Message to be sent out by the workers.
func (*Manager) Run ¶
Run is a blocking function (and hence should be invoked as a goroutine) that scans the source db 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".
func (*Manager) SpawnWorkers ¶
func (m *Manager) SpawnWorkers()
SpawnWorkers spawns workers goroutines that push out messages.