manager

package
v0.5.0-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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

func (m *Manager) AddMessenger(msg messenger.Messenger) error

AddMessenger adds a Messenger messaging backend to the manager.

func (*Manager) GetMessengerNames

func (m *Manager) GetMessengerNames() []string

GetMessengerNames returns the list of registered messengers.

func (*Manager) HasMessenger

func (m *Manager) HasMessenger(id string) bool

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

func (m *Manager) PushMessage(msg Message) error

PushMessage pushes a Message to be sent out by the workers.

func (*Manager) Run

func (m *Manager) Run(tick time.Duration)

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.

func (*Manager) TemplateFuncs

func (m *Manager) TemplateFuncs(c *models.Campaign) template.FuncMap

TemplateFuncs returns the template functions to be applied into compiled campaign templates.

type Message

type Message struct {
	From      string
	To        []string
	Subject   string
	Body      []byte
	Messenger string
}

Message represents a generic message to be pushed to a messenger.

Jump to

Keyboard shortcuts

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