whookie

package module
v0.0.0-...-1d5c36c Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2014 License: MIT Imports: 15 Imported by: 0

README

Whookie

Whookie is a server that sends batched events to subscribed urls, aka Webhooks. If you want to send webhooks from your app, then Whookie can help you out.

This library is designed to be used in an existing Go application. See Whookie Server for a standalone binary.

Usage

Events are pushed to Redis, and batched by the minute. A redis connection string is expected in the environment variable REDIS_URL.

// Supply a poll delay
runner := whookie.NewRunner(time.Second)

…

runner.Stop()

Documentation

Overview

Logger is a simple logging interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	Redis *redis.Client
)

Functions

func NewRunner

func NewRunner(interval time.Duration) runner

Newrunner creates a runner with the supplied interval between polls.

func SetLoggerOutput

func SetLoggerOutput(l Logger, w io.Writer)

Types

type Batch

type Batch struct {
	DomainId  string    `json:"domain_id"`
	Timestamp string    `json:"-"`
	StartedAt time.Time `json:"-"`
	Events    []Event   `json:"events"`
}

Batch represents a group of events that occurred in a given timeperiod for a domain

func (Batch) BlankClone

func (b Batch) BlankClone() Batch

func (Batch) Filtered

func (batch Batch) Filtered(sub Sub) (Batch, bool)

func (Batch) Key

func (b Batch) Key() string

type BatchFinder

type BatchFinder interface {
	ReadyBatchKeys() ([]Batch, error)
	Batch(key string) (Batch, error)
}

BatchFinder is responsible for returning batches ready to process.

type BatchProcessor

type BatchProcessor interface {
	ProcessBatch(Batch) error
}

BatchProcessor is responsible for the processing of batches to their subs.

type BatchSender

type BatchSender interface {
	Send(Batch, Sub)
	Retry(Batch, Sub)
	Fail(Batch, Sub, error)
}

BatchSender is responsible for sending a batch to a sub.

type Event

type Event struct {
	Id        string          `json:"id"`
	Message   string          `json:"message"`
	Type      string          `json:"type"`
	Timestamp int64           `json:"timestamp"`
	Data      json.RawMessage `json:"data"`
}

type HttpBatchSender

type HttpBatchSender struct{}

func (HttpBatchSender) Fail

func (s HttpBatchSender) Fail(batch Batch, sub Sub, err error)

func (HttpBatchSender) Retry

func (s HttpBatchSender) Retry(batch Batch, sub Sub)

Fail is responsible for placing the batch sub combo into failed state and setting retry count, time etc.

func (HttpBatchSender) Send

func (s HttpBatchSender) Send(batch Batch, sub Sub)

Send will submit the batch to the given sub according to the sub configuration. Anything which is considered an error at the client end shall return false, nil Anything which is an error at the server end shall return true, err

type Logger

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

func (Logger) Error

func (l Logger) Error(messages ...interface{})

func (Logger) Errorf

func (l Logger) Errorf(str string, messages ...interface{})

func (Logger) Info

func (l Logger) Info(messages ...interface{})

func (Logger) Infof

func (l Logger) Infof(str string, messages ...interface{})

func (Logger) Notice

func (l Logger) Notice(messages ...interface{})

func (Logger) Noticef

func (l Logger) Noticef(str string, messages ...interface{})

func (Logger) Warning

func (l Logger) Warning(messages ...interface{})

func (Logger) Warningf

func (l Logger) Warningf(str string, messages ...interface{})

type ReadyFinder

type ReadyFinder interface {
	NextReady() (*Batch, *Sub, error)
	ProcessReadyRetries() (int, error)
}

type RedisBatchFinder

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

func (RedisBatchFinder) Batch

func (f RedisBatchFinder) Batch(key string) (Batch, error)

func (RedisBatchFinder) ReadyBatchKeys

func (f RedisBatchFinder) ReadyBatchKeys() ([]Batch, error)

ReadyBatches returns an batches over a minute old from Redis.

type RedisBatchProcessor

type RedisBatchProcessor struct {
}

func (RedisBatchProcessor) PersistBatch

func (p RedisBatchProcessor) PersistBatch(tx *redis.Multi, batch Batch, sub Sub) error

func (RedisBatchProcessor) ProcessBatch

func (p RedisBatchProcessor) ProcessBatch(batch Batch) error

ProcessBatch gets any subs from redis, and sends the batch to the sub.

type RedisReadyFinder

type RedisReadyFinder struct{}

func (RedisReadyFinder) BatchSubFromKey

func (f RedisReadyFinder) BatchSubFromKey(key string) (*Batch, *Sub, error)

func (RedisReadyFinder) NextReady

func (f RedisReadyFinder) NextReady() (*Batch, *Sub, error)

func (RedisReadyFinder) ProcessReadyRetries

func (f RedisReadyFinder) ProcessReadyRetries() (int, error)

type RedisSubFinder

type RedisSubFinder struct {
}

func (RedisSubFinder) Sub

func (f RedisSubFinder) Sub(domainId, id string) (Sub, error)

func (RedisSubFinder) Subs

func (f RedisSubFinder) Subs(domainId string) ([]Sub, error)

type Sub

type Sub struct {
	DomainId string
	Events   []string
	Headers  map[string]string
	URL      string
	Id       string
}

type SubFinder

type SubFinder interface {
	Subs(string) ([]Sub, error)
	Sub(domainId, url string) (Sub, error)
}

Jump to

Keyboard shortcuts

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