mailroom

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: AGPL-3.0 Imports: 21 Imported by: 8

README

mailroom Build Status codecov

About

Mailroom is the RapidPro component responsible for the execution of flows. It interacts directly with the RapidPro database and sends and receives messages with Courier for handling via Redis.

Deploying

As Mailroom is a go application, it compiles to a binary and that binary along with the config file is all you need to run it on your server. You can find bundles for each platform in the releases directory. We recommend running Mailroom behind a reverse proxy such as nginx or Elastic Load Balancer that provides HTTPs encryption.

Configuration

Mailroom uses a tiered configuration system, each option takes precendence over the ones above it:

  1. The configuration file
  2. Environment variables starting with MAILROOM_
  3. Command line parameters

We recommend running Mailroom with no changes to the configuration and no parameters, using only environment variables to configure it. You can use % mailroom --help to see a list of the environment variables and parameters and for more details on each option.

RapidPro Configuration

For use with RapidPro, you will want to configure these settings:

  • MAILROOM_ADDRESS: the address to bind our web server to (default "localhost")
  • MAILROOM_DOMAIN: the domain that mailroom is listening on
  • MAILROOM_AUTH_TOKEN: the token clients will need to authenticate web requests (should match setting in RapidPro)
  • MAILROOM_ATTACHMENT_DOMAIN: the domain that will be used for relative attachments in flows
  • MAILROOM_DB: URL describing how to connect to the RapidPro database (default "postgres://temba:temba@localhost/temba?sslmode=disable")
  • MAILROOM_REDIS: URL describing how to connect to Redis (default "redis://localhost:6379/15")
  • MAILROOM_SMTP_SERVER: the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com

For writing of message attachments, Mailroom needs access to an S3 bucket, you can configure access to your bucket via:

  • MAILROOM_S3_REGION: The region for your S3 bucket (ex: ew-west-1)
  • MAILROOM_S3_MEDIA_BUCKET: The name of your S3 bucket (ex: dl-mailroom)
  • MAILROOM_S3_MEDIA_PREFIX: The prefix to use for filenames of attachments added to your bucket (ex: attachments)
  • MAILROOM_AWS_ACCESS_KEY_ID: The AWS access key id used to authenticate to AWS
  • MAILROOM_AWS_SECRET_ACCESS_KEY The AWS secret access key used to authenticate to AWS

Recommended settings for error and performance monitoring:

  • MAILROOM_LIBRATO_USERNAME: The username to use for logging of events to Librato
  • MAILROOM_LIBRATO_TOKEN: The token to use for logging of events to Librato
  • MAILROOM_SENTRY_DSN: The DSN to use when logging errors to Sentry
  • MAILROOM_LOG_LEVEL: the logging level mailroom should use (default "error", use "debug" for more)

Development

Install Mailroom source in your workspace with:

go get github.com/nyaruka/mailroom

Build Mailroom with:

go build github.com/nyaruka/mailroom/cmd/mailroom

This will create a new executable in your current directory mailroom

To run the tests you need to create the test database:

$ createdb mailroom_test
$ createuser -P -E temba (set no password)

To run all of the tests:

go test github.com/nyaruka/mailroom/... -p=1

Documentation

Index

Constants

This section is empty.

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 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 workers

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   *config.Config
	DB       *sqlx.DB
	RP       *redis.Pool
	S3Client s3iface.S3API

	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 *config.Config) *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 TaskFunction

type TaskFunction func(ctx context.Context, 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 Worker's goroutine and has it start waiting for tasks from the foreman

func (*Worker) Stop

func (w *Worker) Stop()

Stop stops our worker

Jump to

Keyboard shortcuts

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