scheduler

package
v0.15.6 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCanceled = errors.New("canceled")

ErrCanceled is when a scheduled command has been canceled.

View Source
var ScheduledCommandsQueueSize = 100

The default command queue size to use.

Functions

This section is empty.

Types

type Command

type Command interface {
	eh.Command

	// ExecuteAt returns the time when the command will execute.
	ExecuteAt() time.Time
}

Command is a scheduled command with an execution time.

func CommandWithExecuteTime

func CommandWithExecuteTime(cmd eh.Command, t time.Time) Command

CommandWithExecuteTime returns a wrapped command with a execution time set.

type Error

type Error struct {
	// Err is the error that happened when handling the command.
	Err error
	// Ctx is the context used when the error happened.
	Ctx context.Context
	// Command is the command handeled when the error happened.
	Command eh.Command
}

Error is an async error containing the error and the command.

func (*Error) Cause added in v0.15.6

func (e *Error) Cause() error

Cause implements the github.com/pkg/errors Unwrap method.

func (*Error) Error

func (e *Error) Error() string

Error implements the Error method of the error interface.

func (*Error) Unwrap added in v0.15.6

func (e *Error) Unwrap() error

Unwrap implements the errors.Unwrap method.

type PersistedCommand added in v0.15.6

type PersistedCommand struct {
	ID         uuid.UUID       `json:"_"                 bson:"_id"`
	IDStr      string          `json:"id"                bson:"_"`
	RawCommand []byte          `json:"command"           bson:"command"`
	ExecuteAt  time.Time       `json:"timestamp"         bson:"timestamp"`
	Command    eh.Command      `json:"-"                 bson:"-"`
	Context    context.Context `json:"-"                 bson:"-"`
}

PersistedCommand is a persisted command.

func (*PersistedCommand) EntityID added in v0.15.6

func (c *PersistedCommand) EntityID() uuid.UUID

EntityID implements the EntityID method of the eventhorizon.Entity interface.

type Scheduler added in v0.15.6

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

Scheduler is a scheduled of commands.

func NewMiddleware

func NewMiddleware(repo eh.ReadWriteRepo, codec eh.CommandCodec) (eh.CommandHandlerMiddleware, *Scheduler)

NewMiddleware returns a new command handler middleware and a scheduler helper.

func (*Scheduler) CancelCommand added in v0.15.6

func (s *Scheduler) CancelCommand(ctx context.Context, id uuid.UUID) error

CancelCommand cancels a scheduled command.

func (*Scheduler) Commands added in v0.15.6

func (s *Scheduler) Commands(ctx context.Context) ([]*PersistedCommand, error)

Commands returns all scheduled commands.

func (*Scheduler) Errors added in v0.15.6

func (s *Scheduler) Errors() <-chan error

Errors returns an error channel that will receive errors from handling of scheduled commands.

func (*Scheduler) Load added in v0.15.6

func (s *Scheduler) Load(ctx context.Context) error

Load loads all persisted scheduled commands. It will be limited by ScheduledCommandsQueueSize if Start() has not yet been called.

func (*Scheduler) ScheduleCommand added in v0.15.6

func (s *Scheduler) ScheduleCommand(ctx context.Context, cmd eh.Command, executeAt time.Time) (uuid.UUID, error)

ScheduleCommand schedules a command to be executed at `executeAt`. It is persisted to the repo.

func (*Scheduler) Start added in v0.15.6

func (s *Scheduler) Start() error

Start starts the scheduler.

func (*Scheduler) Stop added in v0.15.6

func (s *Scheduler) Stop() error

Stop stops all scheduled commands.

Jump to

Keyboard shortcuts

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