executor

package
v0.0.0-...-e356956 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const ERR_FINISHED = "executor finished"
View Source
const ERR_NOTSTART = "executor is not running"

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor struct {
	Steps []*Step
	// contains filtered or unexported fields
}

Executor just does what's on the label. In Start() you provide (chan *ExecutorUpdate) update channel to get status updates (including step errors! more on them later) carefully relayed from steps via stepchan pump goroutine. on every Tick() It executes every step in order they were added until it reaches the end. Tick() May return unhandled step error or one of two executor's own errors (ERR_FINISHED or ERR_NOTSTART). Errors are pretty descriptive: ERR_FINISHED means it ran out of steps to execute (you're done with task), ERR_NOTSTART means you forgot to Start() When step returns an ExecutorUpdate with "error" step, the stepchan pump relays it to your update channel, stops executor, and shutdowns itself. if you don't do GetLastError (bad for you), the error will still be returned to you by Tick() and then the executor behaves like a stopped one.

func NewExecutor

func NewExecutor() *Executor

func (*Executor) AddStep

func (e *Executor) AddStep(step *Step)

func (*Executor) GetLastError

func (e *Executor) GetLastError() error

func (*Executor) IsRunning

func (e *Executor) IsRunning() bool

func (*Executor) SetContext

func (e *Executor) SetContext(ctx context.Context)

func (*Executor) Start

func (e *Executor) Start(updates chan *ExecutorUpdate)

func (*Executor) Tick

func (e *Executor) Tick() error

type ExecutorUpdate

type ExecutorUpdate struct {
	CurrentStep string
	StepMessage string
}

type Step

type Step struct {
	Id string
	F  func(updates chan *ExecutorUpdate, ctx context.Context) context.Context
}

Like they say: if you break big tasks into smaller ones, then everything's achievable. So step is that one discrete part of a bigger task. You make one with NewStep and feed it to executor. That's it. It's just a freaking fancy wrapper for a function, idk what to document there...

func NewStep

func NewStep(id string, f func(updates chan *ExecutorUpdate, ctx context.Context) context.Context) *Step

func (*Step) Exec

func (s *Step) Exec(ctx context.Context, updates chan *ExecutorUpdate) context.Context

Jump to

Keyboard shortcuts

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