worker

package
v0.0.0-...-32823bc Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

This file contains the generic functions for handling different providers listener's and worker's task. ProcessMail & ProcessLog are identical functions and can be further merged into a single one but that would make managing the code more complex.

package Log Handles Log events pushed on the queue. Whenever a webhook event is recieved it is analysed for the state returned in it, it might happen that few emails are dropped or failed in during transmission by a Email service provider in that case we can retry sending the same email using the original content of the Batch from another provider.

The only caveat of this functionality is, email could have been dropped because of failed MX resolve in which case we will be wasting our bandwidth(todo: resolve MX) Emails can also be dropped if the gateway flags your email as a spam, in that case we should not aggresively retry sending the message as it will degrade the reputation and may cause your Email server to be flagged as a spammer.

Index

Constants

View Source
const MAX_RETRY_COUNT = 6

Variables

View Source
var MailGunClient *http.Client
View Source
var SendGridClient *http.Client

Functions

func GetMgEmailVars

func GetMgEmailVars(options map[string]string, custom_args map[string]string) (string, error)

Creates a JSON body out of options passed to it

func GetSgEmailVars

func GetSgEmailVars(options map[string]string, custom_args map[string]string) (string, error)

Creates a JSON body out of options passed to it

func InitMg

func InitMg()

func InitSg

func InitSg()

func MGListener

func MGListener(packet amqp.Delivery)

func ProcessLog

func ProcessLog(packet amqp.Delivery, provider string, getEmailVarsFunc GetEmailVars, sendRequestFunc SendRequest)

Generic Function to process logs published for retrial @params:

packet : Rabbitmq packet
provider: Provider name i.e. sendgrid, mailgun
routingKey: Routing key intials i.e. "sglog.", "mglog.*"
channel: The channel to which it has to retry publishing
getEmailVarsFunc: A function which will return the body that has to be posted in request
sendRequestFunc: A send helper function which dispatches the request to the known client

func ProcessMail

func ProcessMail(packet amqp.Delivery, currentChannel string, getEmailVarsFunc GetEmailVars, sendRequestFunc SendRequest)

func SGListener

func SGListener(packet amqp.Delivery)

func SendMgRequest

func SendMgRequest(body *string) (int, bool, error)

Sends the request @return

StatusCode int
Nack Packet bool
Error error

func SendSgRequest

func SendSgRequest(body *string) (int, bool, error)

Sends the request @return

StatusCode int
Nack Packet bool
Error error

Types

type GetEmailVars

type GetEmailVars func(map[string]string, map[string]string) (string, error)

type SendRequest

type SendRequest func(*string) (int, bool, error)

Jump to

Keyboard shortcuts

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