mailroom

package module
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: AGPL-3.0 Imports: 12 Imported by: 0

README

mailroom Build Status codecov

GoLang service responsible for handling flow tasks in RapidPro

Documentation

Index

Constants

View Source
const BatchQueue = "batch"
View Source
const HandlerQueue = "handler"

Variables

This section is empty.

Functions

func AddInitFunction

func AddInitFunction(initFunc InitFunction)

AddInitFunction adds an init function that will be called on startup

func AddTaskFunction

func AddTaskFunction(taskType string, taskFunc TaskFunction)

AddTaskFunction adds an task function that will be called for a type of task

Types

type Foreman

type Foreman struct {
	// contains filtered or unexported fields
}

Foreman takes care of managing our set of sending workers and assigns msgs for each to send

func NewForeman

func NewForeman(mr *Mailroom, queue string, maxWorkers int) *Foreman

NewForeman creates a new Foreman for the passed in server with the number of max senders

func (*Foreman) Assign

func (f *Foreman) Assign()

Assign is our main loop for the Foreman, it takes care of popping the next outgoing task from our backend and assigning them to workers

func (*Foreman) Start

func (f *Foreman) Start()

Start starts the foreman and all its workers, assigning jobs while there are some

func (*Foreman) Stop

func (f *Foreman) Stop()

Stop stops the foreman and all its workers, the wait group of the worker can be used to track progress

type InitFunction

type InitFunction func(mr *Mailroom) error

InitFunction is a function that will be called when mailroom starts

type Mailroom

type Mailroom struct {
	Config    *MailroomConfig
	DB        *sqlx.DB
	RP        *redis.Pool
	Quit      chan bool
	CTX       context.Context
	Cancel    context.CancelFunc
	WaitGroup *sync.WaitGroup
	// contains filtered or unexported fields
}

Mailroom is a service for handling RapidPro events

func NewMailroom

func NewMailroom(config *MailroomConfig) *Mailroom

NewMailroom creates and returns a new mailroom instance

func (*Mailroom) Start

func (mr *Mailroom) Start() error

Start starts the mailroom service

func (*Mailroom) Stop

func (mr *Mailroom) Stop() error

Stop stops the mailroom service

type MailroomConfig added in v0.0.33

type MailroomConfig struct {
	SentryDSN  string `help:"the DSN used for logging errors to Sentry"`
	DB         string `help:"URL describing how to connect to the RapidPro database"`
	DBPoolSize int    `help:"the size of our db pool"`
	Redis      string `help:"URL describing how to connect to Redis"`
	Version    string `help:"the version of this mailroom install"`
	LogLevel   string `help:"the logging level courier should use"`
	SMTPServer string `help:"the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com"`

	BatchWorkers   int `help:"the number of go routines that will be used to handle batch events"`
	HandlerWorkers int `help:"the number of go routines that will be used to handle messages"`

	LibratoUsername string `help:"the username that will be used to authenticate to Librato"`
	LibratoToken    string `help:"the token that will be used to authenticate to Librato"`

	AttachmentDomain string `help:"the domain that will be used for relative attachment"`
}

MailroomConfig is our top level configuration object

var Config *MailroomConfig

TODO: better handling of global config Config our global mailroom config

func NewMailroomConfig added in v0.0.33

func NewMailroomConfig() *MailroomConfig

NewMailroomConfig returns a new default configuration object

type TaskFunction

type TaskFunction func(mr *Mailroom, task *queue.Task) error

TaskFunction is the function that will be called for a type of task

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker is our type for a single goroutine that is handling queued events

func NewWorker

func NewWorker(foreman *Foreman, id int) *Worker

NewWorker creates a new worker responsible for working on events

func (*Worker) Start

func (w *Worker) Start()

Start starts our Sender's goroutine and has it start waiting for tasks from the foreman

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops our worker

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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