manager

package
v0.8.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: AGPL-3.0 Imports: 11 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.

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
	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, 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) Close

func (m *Manager) Close()

Close closes and exits the campaign manager.

func (*Manager) HasMessenger

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

HasMessenger checks if a given messenger is registered.

func (*Manager) HasRunningCampaigns

func (m *Manager) HasRunningCampaigns() bool

HasRunningCampaigns checks if there are any active campaigns.

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 (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".

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 {
	messenger.Message
	Subscriber models.Subscriber

	// Messenger is the messenger backend to use: email|postback.
	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