saga

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInstanceNotFound = errors.New("saga not be found")

ErrInstanceNotFound is returned by the saga store if a saga lookup by saga id returns no valid instances

Functions

This section is empty.

Types

type Def

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

Def defines a saga type

func (*Def) HandleEvent

func (sd *Def) HandleEvent(exchange, topic string, event gbus.Message, handler gbus.MessageHandler) error

HandleEvent implements HandlerRegister interface

func (*Def) HandleMessage

func (sd *Def) HandleMessage(message gbus.Message, handler gbus.MessageHandler) error

HandleMessage implements HandlerRegister interface

func (*Def) String

func (sd *Def) String() string

type Glue

type Glue struct {
	*gbus.Glogged
	// contains filtered or unexported fields
}

Glue t/* */ies the incoming messages from the Bus with the needed Saga instances

func NewGlue

func NewGlue(bus gbus.Bus, sagaStore Store, svcName string, txp gbus.TxProvider, getLog func() logrus.FieldLogger, timeoutManager gbus.TimeoutManager) *Glue

NewGlue creates a new Sagamanager

func (*Glue) RegisterSaga

func (imsm *Glue) RegisterSaga(saga gbus.Saga, conf ...gbus.SagaConfFn) error

RegisterSaga registers the saga instance with the Bus

func (*Glue) SagaHandler added in v1.1.1

func (imsm *Glue) SagaHandler(invocation gbus.Invocation, message *gbus.BusMessage) error

SagaHandler is the generic handler invoking saga instances

func (*Glue) Start added in v1.1.0

func (imsm *Glue) Start() error

Start starts the glue instance up

func (*Glue) Stop added in v1.1.0

func (imsm *Glue) Stop() error

Stop starts the glue instance up

func (*Glue) TimeoutSaga added in v1.1.0

func (imsm *Glue) TimeoutSaga(tx *sql.Tx, sagaID string) error

TimeoutSaga fetches a saga instance and calls its timeout interface

type Instance

type Instance struct {
	ID                 string
	ConcurrencyCtrl    int
	UnderlyingInstance gbus.Saga
	MsgToMethodMap     []*MsgToFuncPair

	/*
		Will hold the service name that sent the command or event that started the saga
	*/
	StartedBy string
	/*
		If this saga has been started by a message originating from another saga instance
		this field will hold the saga_id of that instance
	*/
	StartedBySaga string

	//StartedByMessageID the message-id of the message that created the saga
	StartedByMessageID string
	//StartedByRPCID the rpc id of the message that created the saga
	StartedByRPCID string

	//CreatedAt the time.Now() timestamp when the saga was created
	CreatedAt time.Time
	// contains filtered or unexported fields
}

Instance represent a living instance of a saga of a particular definition

func NewInstance

func NewInstance(sagaType reflect.Type, msgToMethodMap []*MsgToFuncPair) *Instance

NewInstance creates a new saga instance

func (*Instance) String

func (si *Instance) String() string

type MsgToFuncPair

type MsgToFuncPair struct {
	Filter       *gbus.MessageFilter
	SagaFuncName string
}

MsgToFuncPair helper struct

type Store

type Store interface {
	gbus.Logged
	RegisterSagaType(saga gbus.Saga)
	GetSagaByID(tx *sql.Tx, sagaID string) (*Instance, error)
	GetSagasByType(tx *sql.Tx, sagaType reflect.Type) ([]*Instance, error)
	SaveNewSaga(tx *sql.Tx, sagaType reflect.Type, newInstance *Instance) error
	UpdateSaga(tx *sql.Tx, instance *Instance) error
	DeleteSaga(tx *sql.Tx, instance *Instance) error
	Purge() error
}

Store abtracts the way sagas get persisted

Jump to

Keyboard shortcuts

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