projection

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Start = new(emptypb.Empty)

Start is used to start the projection

Functions

This section is empty.

Types

type DiscardHandler

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

DiscardHandler implements the projection Handler interface This handler really does nothing with the consumed event Note: this will be useful when writing unit tests

func NewDiscardHandler

func NewDiscardHandler(logger log.Logger) *DiscardHandler

NewDiscardHandler creates an instance of DiscardHandler

func (*DiscardHandler) EventsCount

func (x *DiscardHandler) EventsCount() int

EventsCount returns the number of events processed

func (*DiscardHandler) Handle

func (x *DiscardHandler) Handle(_ context.Context, persistenceID string, event *anypb.Any, state *anypb.Any, revision uint64) error

Handle handles the events consumed

type Handler

type Handler interface {
	// Handle handles the event that is consumed by the projection
	Handle(ctx context.Context, persistenceID string, event *anypb.Any, state *anypb.Any, revision uint64) error
}

Handler is used to handle event and state consumed from the event store

type Option

type Option interface {
	// Apply sets the Option value of a config.
	Apply(runner *runner)
}

Option is the interface that applies a configuration option.

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the actor system custom log

func WithMaxBufferSize

func WithMaxBufferSize(bufferSize int) Option

WithMaxBufferSize sets the max buffer size. This defines how many events are fetched on a single run of the projection

func WithRecoveryStrategy

func WithRecoveryStrategy(strategy *Recovery) Option

WithRecoveryStrategy sets the recovery strategy

func WithRefreshInterval

func WithRefreshInterval(interval time.Duration) Option

WithRefreshInterval sets the refresh interval

func WithResetOffset

func WithResetOffset(resetOffset time.Time) Option

WithResetOffset helps reset the offset to a given timestamp.

func WithStartOffset

func WithStartOffset(startOffset time.Time) Option

WithStartOffset sets the starting point where to read the events

type OptionFunc

type OptionFunc func(*runner)

OptionFunc implements the Option interface.

func (OptionFunc) Apply

func (f OptionFunc) Apply(runner *runner)

Apply applies the options to Engine

type Projection

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

Projection defines the projection actor Only a single instance of this will run throughout the cluster

func New

func New(name string,
	handler Handler,
	eventsStore eventstore.EventsStore,
	offsetStore offsetstore.OffsetStore,
	opts ...Option) *Projection

New creates an instance of Projection

func (*Projection) PostStop

func (x *Projection) PostStop(ctx context.Context) error

PostStop prepares the actor to gracefully shutdown

func (*Projection) PreStart

func (x *Projection) PreStart(ctx context.Context) error

PreStart prepares the projection

func (*Projection) Receive

func (x *Projection) Receive(ctx actors.ReceiveContext)

Receive handle the message sent to the projection actor

type Recovery

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

Recovery specifies the various recovery settings of a projection The option helps defines what happens when the projection handler fails to process the consumed event for a given persistence id

func NewRecovery

func NewRecovery(options ...RecoveryOption) *Recovery

NewRecovery creates an instance of Recovery

func (Recovery) RecoveryPolicy

func (c Recovery) RecoveryPolicy() RecoveryPolicy

RecoveryPolicy returns the recovery policy

func (Recovery) Retries

func (c Recovery) Retries() uint64

Retries returns the number of times to retry handler function.

func (Recovery) RetryDelay

func (c Recovery) RetryDelay() time.Duration

RetryDelay returns the delay between retry attempts

type RecoveryOption

type RecoveryOption interface {
	// Apply sets the RecoveryOption value of a recovery.
	Apply(recovery *Recovery)
}

RecoveryOption is the interface that applies a recovery option.

func WithRecoveryPolicy

func WithRecoveryPolicy(policy RecoveryPolicy) RecoveryOption

WithRecoveryPolicy sets the recovery policy

func WithRetries

func WithRetries(retries uint64) RecoveryOption

WithRetries sets the number of retries

func WithRetryDelay

func WithRetryDelay(delay time.Duration) RecoveryOption

WithRetryDelay sets the retry delay

type RecoveryOptionFunc

type RecoveryOptionFunc func(recovery *Recovery)

RecoveryOptionFunc implements the RecoveryOption interface.

func (RecoveryOptionFunc) Apply

func (f RecoveryOptionFunc) Apply(c *Recovery)

type RecoveryPolicy

type RecoveryPolicy int

RecoveryPolicy defines the various policies to apply when a given projection panic

const (
	// Fail states that if the first attempt to invoke the handler fails
	// it will immediately give up and fail the projection
	Fail RecoveryPolicy = iota
	// RetryAndFail states that if the first attempt to invoke the handler fails it will retry invoking the handler with the
	// same envelope this number of `retries` with the `delay` between each attempt. It will give up
	// and fail the projection if all attempts fail. For this to work as expected one need to define the `retries` and `delay`
	// settings in the projection configuration.
	RetryAndFail
	// Skip states that if the first attempt to invoke the handler fails it will immediately give up, discard the envelope and
	// continue with next. This will commit the offset assuming the event has been successfully processed.
	// Use this strategy with care.
	Skip
	// RetryAndSkip states that if the first attempt to invoke the handler fails it will retry invoking the handler with the
	// same envelope this number of `retries` with the `delay` between each attempt. It will give up,
	// discard the element and continue with next if all attempts fail.
	// For this to work as expected one need to define the `retries` and `delay` settings in the projection configuration
	RetryAndSkip
)

Jump to

Keyboard shortcuts

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