Documentation ¶
Index ¶
- Variables
- type Command
- type Error
- type PersistedCommand
- type Scheduler
- func (s *Scheduler) CancelCommand(ctx context.Context, id uuid.UUID) error
- func (s *Scheduler) Commands(ctx context.Context) ([]*PersistedCommand, error)
- func (s *Scheduler) Errors() <-chan error
- func (s *Scheduler) Load(ctx context.Context) error
- func (s *Scheduler) ScheduleCommand(ctx context.Context, cmd eh.Command, executeAt time.Time) (uuid.UUID, error)
- func (s *Scheduler) Start() error
- func (s *Scheduler) Stop() error
Constants ¶
This section is empty.
Variables ¶
var ErrCanceled = errors.New("canceled")
ErrCanceled is when a scheduled command has been canceled.
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.
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.
type PersistedCommand ¶ added in v0.18.0
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.18.0
func (c *PersistedCommand) EntityID() uuid.UUID
EntityID implements the EntityID method of the eventhorizon.Entity interface.
type Scheduler ¶ added in v0.18.0
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.18.0
CancelCommand cancels a scheduled command.
func (*Scheduler) Commands ¶ added in v0.18.0
func (s *Scheduler) Commands(ctx context.Context) ([]*PersistedCommand, error)
Commands returns all scheduled commands.
func (*Scheduler) Errors ¶ added in v0.18.0
Errors returns an error channel that will receive errors from handling of scheduled commands.
func (*Scheduler) Load ¶ added in v0.18.0
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.18.0
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.