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.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 Services. For any sequence, there will be two agents in play: one for the startup 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 Services.
func (*Agent) Down ¶
Down runs the shutdown sequence. Down returns an error if the Agent's current state doesn't allow the sequence to start.
func (*Agent) Progress ¶
Progress allows the caller to receive progress reports over a channel. Progress returns a channel that will receive a Progress struct every time a Service 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 Service in the sequence (plus one more to mark the end of execution), or if execution stops short, the last progress report sent will contain an error.
func (*Agent) ServiceCount ¶
ServiceCount returns the number of services currently registered with the Agent.
func (*Agent) String ¶
String returns a string representation of the registered Services ordered by priority. Service names are wrapped in parentheses, and separated by a colon when it might run concurrently with one or more other services, and a right-arrow when it will run before another service. Services that have the same priority are sorted alphabetically for reasons of reproducibility.
type CalleeError ¶
type CalleeError string
CalleeError indicates that a "callee" was called after another one already has been called: Wait/Progress.
func (CalleeError) Error ¶
func (c CalleeError) Error() string
Error returns the error message for a CalleeError.
type CyclicReferenceError ¶
type CyclicReferenceError string
CyclicReferenceError indicates that two Services are referencing each other.
func (CyclicReferenceError) Error ¶
func (c CyclicReferenceError) Error() string
Error returns the error message for a CyclicReferenceError.
type EmptySequenceError ¶
type EmptySequenceError string
EmptySequenceError indicates an empty boot sequence.
func (EmptySequenceError) Error ¶
func (e EmptySequenceError) Error() string
Error returns the error message for a EmptySequenceError.
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 InvalidStateError ¶
type InvalidStateError string
InvalidStateError indicates that the Agent was unable to run the boot sequence, either because it is already running, or because it has already completed.
func (InvalidStateError) Error ¶
func (i InvalidStateError) Error() string
Error returns the error message for a InvalidStateError.
type Manager ¶
type Manager struct { sync.Mutex // Protects field services. // contains filtered or unexported fields }
Manager provides registration and storage of boot sequence Services. Manager can instantiate an Agent, which is responsible for running the actual startup and shutdown sequences.
func (*Manager) Agent ¶
Agent orders the registered services by priority and returns an Agent for controlling the startup and shutdown sequences. Agent returns an error if any of the registered Services refer to other Services that are not registered.
func (*Manager) Register ¶
Register registers 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. Add returns a pointer to the added Service, that you can call After() on, in order to influence order of execution.
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.
type NilFuncError ¶
type NilFuncError string
NilFuncError indicates that a Service contains one or more nil Funcs.
func (NilFuncError) Error ¶
func (n NilFuncError) Error() string
Error returns the error message for a CalleeError.
type Progress ¶
Progress is the boot sequence feedback medium. Progress is communicated on channels returned by methods Up() and Down() and provides feedback on the current progress of the boot sequence. This includes the name of the Service that was last executed, along with an optional error if the Service Func failed. Err will be nil on success. Progress satisfies the error interface.
type SelfReferenceError ¶
type SelfReferenceError string
SelfReferenceError indicates a service that references itself in an After method call.
func (SelfReferenceError) Error ¶
func (s SelfReferenceError) Error() string
Error returns the error message for a SelfReferenceError.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service contains the functions required in order to execute a single Service Func in a sequence, the up() and down() functions, respectively.
type UnregisteredServiceError ¶
type UnregisteredServiceError string
UnregisteredServiceError indicates a service has not been registered with the boot sequence manager.
func (UnregisteredServiceError) Error ¶
func (u UnregisteredServiceError) Error() string
Error returns the error message for a UnregisteredServiceError.