Documentation ¶
Overview ¶
Package bootseq provides a general-purpose boot sequence manager with separate startup/shutdown phases, cancellation and a simple abstraction that allows easy control over execution order and concurrency.
Quick Start
seq := bootseq.New("My Boot Sequence") seq.Add("some-service", someServiceUp, someServiceDown) seq.Add("other-service", otherServiceUp, otherServiceDown) seq.Add("third-service", thirdServiceUp, thirdServiceDown) // Execute "some-service" and "other-service" concurrently, followed by "third-service". seq.Sequence("(some-service : other-service) > third-service") up := seq.Up(context.Background()) up.Wait() // Your application is now ready! down := up.Down(context.Background()) down.Wait()
Please refer to the enclosed README for more details.
Example (Basic) ¶
package main import ( "context" "fmt" "github.com/mkock/bootseq" "strings" ) func main() { // Let's use a boot sequence to construct a sentence! // For the shutdown sequence, we'll "deconstruct" it by removing each word. var words []string add := func(word string) func() error { return func() error { words = append(words, word) return nil } } rm := func() error { words = words[:len(words)-1] return nil } seq := bootseq.New("Basic Example") seq.Add("welcome", add("Welcome"), rm) seq.Add("to", add("to"), rm) seq.Add("my", add("my"), rm) seq.Add("world", add("world!"), rm) i, err := seq.Sequence("welcome > to > my > world") if err != nil { panic(err) } // Bootup sequence. up := i.Up(context.Background()) up.Wait() fmt.Println(strings.Join(words, " ")) // Shutdown sequence. down := up.Down(context.Background()) down.Wait() fmt.Println(strings.Join(words, " ")) }
Output: Welcome to my world!
Example (Progress) ¶
package main import ( "github.com/mkock/bootseq" ) func main() { bootseq.New("Boot it!") // ... }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errop ¶
func Errop() error
Errop (error operation) is a convenience function you can use in place of a step function for when you want a function that returns an error.
func Noop ¶
func Noop() error
Noop (no operation) is a convenience function you can use in place of a step function for when you want a function that does nothing.
Types ¶
type Agent ¶
type Agent struct { sync.Mutex // Controls access to Agent.callee. // contains filtered or unexported fields }
Agent represents the execution of a sequence of steps. For any sequence, there will be two agents in play: one for the bootup sequence, and another for the shutdown sequence. The only difference between these two is the order in which the sequence is executed. Each agent keeps track of its progress and handles execution of sequence steps.
func (*Agent) Down ¶
Down starts the shutdown sequence. It returns a new agent for controlling and monitoring execution of the sequence.
func (*Agent) Progress ¶
Progress returns a channel that will receive a Progress struct every time a step in the boot sequence has completed. In case of an error, execution will stop and no further progress reports will be sent. Consequently, there will either be a progress report for each step in the sequence, or if execution stops short, the last progress report sent will contain an error.
type ErrParsingFormula ¶
type ErrParsingFormula struct {
// contains filtered or unexported fields
}
ErrParsingFormula represents a parse problem with the formula to the Sequence() method.
func (ErrParsingFormula) Error ¶
func (e ErrParsingFormula) Error() string
Error satisfies the error interface by returning an error message with parse error details.
type Func ¶
type Func func() error
Func is the type used for any function that can be executed as a service in a boot sequence. Any function that you wish to register and execute as a service must satisfy this type.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance contains the actual sequence of steps that need to be performed during execution of the boot sequence. It also keeps track of progress along the way, and provides the Up() method for starting the boot sequence.
func (Instance) CountSteps ¶
CountSteps returns the number of steps currently added to the Instance. It counts steps recursively, covering all sub-steps. The count is for a single sequence (up/down), so you'll need to multiply this number by two to cover both sequences.
type Manager ¶
type Manager struct { Name string // contains filtered or unexported fields }
Manager represents a single boot sequence with its own name. Actual up/down functions are stored (and referenced) by name in the map services.
func (Manager) Add ¶
Add adds a single named service to the boot sequence, with the given "up" and "down" functions. If a service with the given name already exists, the provided up- and down functions replace those already registered.
func (Manager) Sequence ¶
Sequence takes a formula (see package-level comment) and returns an Instance that acts as the main struct for calling Up() and keeping track of progress.
func (Manager) ServiceCount ¶
ServiceCount returns the number of services currently registered with the Manager.
func (Manager) ServiceNames ¶
ServiceNames returns the name of each registered service, in no particular order.