gotell

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 3 Imported by: 0

README

go-tell

What is this?

Go-tell is a set of opinionated interfaces and structs intended to be used as building blocks for a notification system.

The blocks are intended to be constructed as so:

Source -> Store <--> Worker -> Sender
Source
  • A source knows how to receive a job and save to a store
Store

A store is made up of two parts;

  • Store is the behavioural operations tailored specifically to managing jobs.
  • Storage is the 'CRUD' operations used for jobs.
Worker
  • A worker knows how to 'handle' a job from a store to a specific sender interface.
  • A worker has a 'strategy' to manage jobs if they fail
Sender
  • A sender tries to send and stops on failure.
  • Inspired by the sender interfaces at 'github.com/appscode/go-notify', there's a wrapper for them.

So what can I even with this?

For now, there's a lot of plumbing required. This is only a library with a shared set of interfaces that -you- need to put together.

Check the examples for simple implementations.

TODO

  • Add sources
  • More default job handlers
  • Pass error handling behaviour through to a worker
  • Have a default set of error handling behaviours for workers
  • Option to have environment configurations as defaults for stores/senders/sources
  • A full system (cmd/main.go)

Documentation

Index

Constants

View Source
const (
	JobTypeSMS   = "SMS"
	JobTypeEmail = "Email"
	JobTypeChat  = "Chat"
	JobTypeApi   = "Api"
)
View Source
const StatusJobComplete = "complete"
View Source
const StatusJobCreated = ""
View Source
const StatusJobError = "error"
View Source
const StatusJobPending = "pending"

Variables

View Source
var (
	ErrorNoJobFound = errors.New("no job found")
)

Functions

This section is empty.

Types

type Job

type Job struct {
	ID        uuid.UUID
	Type      string // "email", "sms", "chat" , ?
	Status    string
	RelatedId string
	Data      JobData

	// Failure Information
	RetryCount int
	Created    time.Time
}

Job stores the state and raw information to turn it into a task to be executed.

func BuildAPIJob

func BuildAPIJob(payload string, relatedId string) (Job, error)

func BuildChatJob

func BuildChatJob(body string, relatedId string, to ...string) (*Job, error)

func BuildEmailJob

func BuildEmailJob(from, subject, body, tag string, tracking, isHTML bool, attachments map[string][]byte, relatedId string, to ...string) (*Job, error)

BuildEmailJob from is email subject is string max len?? to is email

func BuildSMSJob

func BuildSMSJob(from, body string, relatedId string, to ...string) (Job, error)

BuildSMSJob from is a phone number body is the content to is a list of target phone numbers

func (Job) Clone

func (job Job) Clone() Job

type JobData

type JobData struct {
	From        string
	Subject     string
	Body        string
	Tag         string
	Tracking    bool
	HTML        bool
	To          string
	CC          []string
	Attachments map[string][]byte
}

func (JobData) String

func (d JobData) String() string

Human representation of a job.

type JobHandler

type JobHandler func(job Job) error

type Storage

type Storage interface {
	AddJob(job *Job) error
	GetJob() (*Job, error)
	UpdateJob(job *Job) error
	DeleteJob(job *Job) error
}

type Store

type Store interface {
	Storage
	WaitToDoJob() (chan *Job, error)
	StopWaiting(chan *Job)
	CompleteJob(job *Job) error
	ReturnJob(job *Job) error
	FailedJob(job *Job) error
}

Directories

Path Synopsis
api
sms
mem

Jump to

Keyboard shortcuts

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