mongodb

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGracefulContext

func NewGracefulContext(ctx context.Context, idle, forceAfter time.Duration) (
	c context.Context,
	keepAlive func(),
	cancel func(),
)

NewGracefulContext will create a GracefulContext with an idle time which should be longer than a typical operation cadence, and a "force after" duration which should be long enough to let some amount of operations to finish.

Types

type GracefulContext

type GracefulContext struct {
	context.Context
	// contains filtered or unexported fields
}

GracefulContext is a context that can be gracefully cancelled after the original context has been canceled, but with a grace period to let operations finish. The KeepAlive method should be used to signal that operations are still ongoing.

func (*GracefulContext) Done

func (g *GracefulContext) Done() <-chan struct{}

Done implements the Done method of the context.Context interface.

type Option

type Option func(*Outbox) error

Option is an option setter used to configure creation.

func WithCollectionName

func WithCollectionName(outboxColl string) Option

WithCollectionName uses different collections from the default "outbox" collection.

func WithPeriodicCleanupAge

func WithPeriodicCleanupAge(age time.Duration) Option

WithPeriodicCleanupAge sets the age at which the periodic cleanup is run. The default value is 10 minutes.

func WithPeriodicSweepAge

func WithPeriodicSweepAge(age time.Duration) Option

WithPeriodicSweepAge sets the age at which the periodic sweep is run. The default value is 15 seconds.

func WithPeriodicSweepInterval

func WithPeriodicSweepInterval(interval time.Duration) Option

WithPeriodicSweepInterval sets the interval at which the periodic sweep is run. The default value is 15 seconds.

func WithWatchToken

func WithWatchToken(token string) Option

WithWatchToken sets a token, used for watching outbox events stored with the same token. This can be used to let parts of a system watch their own events by setting a common token, for example a service name. If each host should watch their local events the hostname can often be used.

type Outbox

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

Outbox implements an eventhorizon.Outbox for MongoDB.

func NewMongoDBOutbox

func NewMongoDBOutbox(db eh.MongoDB, options ...Option) (*Outbox, error)

NewOutboxWithClient creates a new Outbox with a client.

func NewOutbox

func NewOutbox(uri, dbName string, options ...Option) (*Outbox, error)

NewOutbox creates a new Outbox with a MongoDB URI: `mongodb://hostname`.

func NewOutboxWithClient

func NewOutboxWithClient(client *mongo.Client, dbName string, options ...Option) (*Outbox, error)

NewOutboxWithClient creates a new Outbox with a client.

func (*Outbox) AddHandler

func (o *Outbox) AddHandler(_ context.Context, m eh.EventMatcher, h eh.EventHandler) error

AddHandler implements the AddHandler method of the eventhorizon.Outbox interface.

func (*Outbox) Close

func (o *Outbox) Close() error

Close implements the Close method of the eventhorizon.EventBus interface.

func (*Outbox) CollectionName

func (o *Outbox) CollectionName() string

EventsCollectionName returns the name of the outbox collection.

func (*Outbox) Errors

func (o *Outbox) Errors() <-chan error

Errors implements the Errors method of the eventhorizon.EventBus interface.

func (*Outbox) HandleEvent

func (o *Outbox) HandleEvent(ctx context.Context, event eh.Event) error

HandleEvent implements the HandleEvent method of the eventhorizon.EventHandler interface.

func (*Outbox) HandlerType

func (o *Outbox) HandlerType() eh.EventHandlerType

HandlerType implements the HandlerType method of the eventhorizon.EventHandler interface.

func (*Outbox) Start

func (o *Outbox) Start()

Start implements the Start method of the eventhorizon.Outbox interface.

Jump to

Keyboard shortcuts

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