action

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingBus is returned when trying to publish an event without an
	// event.Bus or dispatch a Command without a command.Bus.
	ErrMissingBus = errors.New("missing bus")

	// ErrMissingRepository is returned when trying to fetch an aggregate with
	// an .
	ErrMissingRepository = errors.New("missing repository")
)

Functions

This section is empty.

Types

type Action

type Action interface {
	// Name returns the name of the Action.
	Name() string

	// Run runs the Action.
	Run(Context) error
}

Action is a SAGA action.

func New

func New(name string, run func(Context) error) Action

New returns a new Action with the given name and runner.

type Context

type Context interface {
	context.Context

	// Action returns the currently executed Action.
	Action() Action

	// Publish publishes the given events via the underlying Event Bus. If no
	// Event Bus is available, Publish returns ErrMissingBus.
	Publish(context.Context, ...event.Event) error

	// Dispatch synchronously dispatches the given Command via the underlying
	// Command Bus. If no Command Bus is available, Dispatch returns ErrMissingBus.
	Dispatch(context.Context, command.Command, ...command.DispatchOption) error

	// Fetch fetches the provided aggregate from the underlying Aggregate
	// Repository. If no aggregate Repository is available, Fetch returns
	// ErrMissingRepository.
	Fetch(context.Context, aggregate.Aggregate) error

	// Run runs the Action with the specified name.
	Run(context.Context, string) error
}

Context is the context for running actions.

func NewContext

func NewContext(parent context.Context, act Action, opts ...ContextOption) Context

NewContext returns a new Context for the given Action.

type ContextOption

type ContextOption func(*actionContext)

A ContextOption configures a Context.

func WithCommandBus

func WithCommandBus(bus command.Bus) ContextOption

WithCommandBus returns a ContextOption that provides the Context with a command.Bus.

func WithEventBus

func WithEventBus(bus event.Bus) ContextOption

WithEventBus returns a ContextOption that provides the Context with an event.Bus.

func WithRepository

func WithRepository(r aggregate.Repository) ContextOption

WithRepository returns a ContextOption that provides the Context with an .

func WithRunner

func WithRunner(run func(context.Context, string) error) ContextOption

WithRunner returns a ContextOption that specifies the runner function that is called when ctx.Run is called.

type Option

type Option func(*Report)

An Option adds information to a Report.

func CompensatedBy

func CompensatedBy(rep Report) Option

CompensatedBy returns a Option that adds the Report of a compensating Action to the Report of a failed Action.

func Error

func Error(err error) Option

Error returns a Option that adds the error of an Action to a Report.

type Report

type Report struct {
	Action      Action
	Start       time.Time
	End         time.Time
	Runtime     time.Duration
	Error       error
	Compensator *Report
}

Report represents a report of an action. It contains information about the action, including start and end time, runtime, error (if any), and compensator (if any). Additional information can be added using Options. Use NewReport to create a new Report.

func NewReport

func NewReport(act Action, start, end time.Time, opts ...Option) Report

NewReport returns a Report for the given Action. The returned Report provides at least the Action and its start-, end- & runtime. Additional information can be added by providing Options.

Jump to

Keyboard shortcuts

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