notificationqueue

package
v0.0.0-...-803885c Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: MIT Imports: 7 Imported by: 7

Documentation

Index

Constants

View Source
const DirectiveNameCommon = "common"

Variables

View Source
var ErrIDGeneratorRequired = errors.New("id generator required")

ErrIDGeneratorRequired id generator required

View Source
var ErrQueueDriverRequired = errors.New("queue driver required")

ErrQueueDriverRequired queue driver required error.

View Source
var FactoryCommon = func(loader func(v interface{}) error) (Directive, error) {
	c := &CommonConfig{}
	err := loader(c)
	if err != nil {
		return nil, err
	}
	return c, nil
}

Functions

func Factories

func Factories() []string

Factories returns a sorted list of the names of the registered factories.

func NopExecutionHandler

func NopExecutionHandler(e *Execution)

NopExecutionHandler nop execution handelr

func NopIDGenerator

func NopIDGenerator() (string, error)

NopIDGenerator nop id gererator

func NopNotificationHandler

func NopNotificationHandler(n *notification.Notification)

NopNotificationHandler nop notification heandler

func NopReceiptHanlder

func NopReceiptHanlder(*Receipt)

NopReceiptHanlder nop receipt hanlder

func NopRecover

func NopRecover()

NopRecover noop recover

func Register

func Register(name string, f Factory)

Register makes a directive factory available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

func UnregisterAll

func UnregisterAll()

UnregisterAll unregister all driver

Types

type CommonConfig

type CommonConfig struct {
	Workers int
}

func (*CommonConfig) AppylToPublisher

func (c *CommonConfig) AppylToPublisher(p *Publisher) error

type Config

type Config struct {
	Directives []*DirectiveConfig
}

Config publisher config

func (*Config) ApplyTo

func (c *Config) ApplyTo(p *Publisher) error

ApplyTo apply config to publisher

type Directive

type Directive interface {
	//AppylToPublisher applu directive to publisher
	AppylToPublisher(*Publisher) error
}

Directive publisher directive

func NewDirective

func NewDirective(name string, loader func(v interface{}) error) (Directive, error)

NewDirective create new directive with given name loader. Reutrn directive created and any error if raised.

type DirectiveConfig

type DirectiveConfig struct {
	//Directive directive keyword
	Directive string
	//DirectiveConfig directive config
	DirectiveConfig func(v interface{}) error `config:", lazyload"`
}

DirectiveConfig Directive config

type DirectiveFunc

type DirectiveFunc func(*Publisher) error

DirectiveFunc directive func

func (DirectiveFunc) AppylToPublisher

func (f DirectiveFunc) AppylToPublisher(p *Publisher) error

AppylToPublisher applu directive to publisher

type Execution

type Execution struct {
	//ExecutionID execition id
	ExecutionID string
	//Notification notification to execute
	Notification *notification.Notification
	//RetryCount retry count
	RetryCount int32
	//StartTime execution start time
	StartTime int64
	//RetryAfterTime execution retry after time
	RetryAfterTime int64
}

Execution notification Execution

func NewExecution

func NewExecution() *Execution

NewExecution create new execution

type Factory

type Factory func(loader func(v interface{}) error) (Directive, error)

Factory directive factory

type NopQueue

type NopQueue struct {
}

NopQueue struct

func (*NopQueue) AttachTo

func (*NopQueue) AttachTo(*Notifier) error

AttachTo attach queue to notifier

func (*NopQueue) Detach

func (*NopQueue) Detach() error

Detach detach queue.

func (*NopQueue) PopChan

func (*NopQueue) PopChan() (<-chan *Execution, error)

PopChan return execution chan

func (*NopQueue) Push

Push push notification to queue

func (*NopQueue) Remove

func (*NopQueue) Remove(nid string) error

Remove remove notification by given id

func (*NopQueue) Start

func (*NopQueue) Start() error

Start start queue

func (*NopQueue) Stop

func (*NopQueue) Stop() error

Stop stop queue

type Notifier

type Notifier struct {
	//DeliveryCenter
	notificationdelivery.DeliveryCenter
	//Workers push workers num
	Workers int

	//IDGenerator id generator
	IDGenerator func() (string, error)
	//OnNotification notification handler
	OnNotification func(*notification.Notification)
	//OnReceipt receipt handler
	OnReceipt func(*Receipt)
	//OnExecution execution handler
	OnExecution func(*Execution)
	//Recover recover handler
	Recover func()
	// contains filtered or unexported fields
}

Notifier notifier struct

func NewNotifier

func NewNotifier() *Notifier

NewNotifier create new notifier

func (*Notifier) HandleDeliverTimeout

func (notifier *Notifier) HandleDeliverTimeout(e *Execution)

HandleDeliverTimeout deliver timeout handler

func (*Notifier) HandleRetryTooMany

func (notifier *Notifier) HandleRetryTooMany(e *Execution)

HandleRetryTooMany retry toomany handler

func (*Notifier) InitNotification

func (notifier *Notifier) InitNotification(n *notification.Notification) error

func (*Notifier) Notify

func (notifier *Notifier) Notify(n *notification.Notification) error

Notify delivery notification Notification id will be returned

func (*Notifier) Queue

func (notifier *Notifier) Queue() Queue

Queue return notifier queue.

func (*Notifier) Reset

func (notifier *Notifier) Reset()

Reset reset notifier handlers

func (*Notifier) SetQueue

func (notifier *Notifier) SetQueue(q Queue)

SetQueue set queue to notifier. SetQueue should be called before start

func (*Notifier) Start

func (notifier *Notifier) Start() error

Start start notifier

func (*Notifier) Stop

func (notifier *Notifier) Stop() error

Stop stop notifier

type Publisher

type Publisher struct {
	//DraftReviewer checker that check if given notification should be published or put in draft box.
	//Return true if notification should sendt to draftbox
	//Default value is CheckerDraftModeHeader
	DraftReviewer notification.Checker
	Draftbox      notification.Store
	*Notifier
}

Publisher publisher struct

func NewPublisher

func NewPublisher() *Publisher

NewPublisher create new publisher

func (*Publisher) DraftboxLoader

func (publisher *Publisher) DraftboxLoader() notification.Store

DraftboxLoader draftbox loader

func (*Publisher) PublishDraft

func (publisher *Publisher) PublishDraft(nid string) (*notification.Notification, error)

PublishDraft publish notificaiton by given id. Notification.ErrNotificationIDNotFound will be returned if nid not found.

func (*Publisher) PublishNotification

func (publisher *Publisher) PublishNotification(n *notification.Notification) (string, bool, error)

PublishNotification generate notification id and publish given notification Return notification id and if notification is published.

func (*Publisher) Start

func (publisher *Publisher) Start() error

Start start publisher

func (*Publisher) Stop

func (publisher *Publisher) Stop() error

Stop stop publisher

type Queue

type Queue interface {
	//PopChan return execution chan
	PopChan() (<-chan *Execution, error)
	//Push push notification to queue
	Push(*notification.Notification) error
	//Remove remove notification by given id
	Remove(nid string) error
	//Start start queue
	Start() error
	//Stop stop queue
	Stop() error
	//AttachTo attach queue to notifier
	AttachTo(*Notifier) error
	//Detach detach queue.
	Detach() error
}

Queue notification deliver queue

type Receipt

type Receipt struct {
	//NotificationID notification id
	Notification *notification.Notification
	//ExecutionID notification execution id
	ExecutionID string
	//Status delivery status
	Status notificationdelivery.DeliveryStatus
	//Message. receipt for successfully delivery or resofn fail fail delivery
	Message string
}

Receipt notification receipt struct

func NewReceipt

func NewReceipt() *Receipt

NewReceipt create new receipt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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