Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface { // Unit for Group registration and identification Unit // FlagSet returns an object's FlagSet FlagSet() *FlagSet // Validate checks an object's stored values Validate() error }
Config interface should be implemented by Group Unit objects that manage their own configuration through the use of flags. If a Unit's Validate returns an error it will stop the Group immediately.
type FlagSet ¶
FlagSet holds a pflag.FlagSet as well as an exported Name variable for allowing improved help usage information.
func NewFlagSet ¶
NewFlagSet returns a new FlagSet for usage in Config objects.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group builds on https://github.com/oklog/run to provide a deterministic way to manage service lifecycles. It allows for easy composition of elegant monoliths as well as adding signal handlers, metrics services, etc.
func (Group) ListUnits ¶
ListUnits returns a list of all Group phases and the Units registered to each of them.
func (*Group) Register ¶
Register will inspect the provided objects implementing the Unit interface to see if it needs to register the objects for any of the Group bootstrap phases. If a Unit doesn't satisfy any of the bootstrap phases it is ignored by Group. The returned array of booleans is of the same size as the amount of provided Units, signalling for each provided Unit if it successfully registered with Group for at least one of the bootstrap phases or if it was ignored.
func (*Group) RegisterFlags ¶
func (*Group) Run ¶
Run will execute all phases of all registered Units and block until an error occurs. If RunConfig has been called prior to Run, the Group's Config phase will be skipped and Run continues with the PreRunner and Service phases.
The following phases are executed in the following sequence:
Config phase (serially, in order of Unit registration) - FlagSet() Get & register all FlagSets from Config Units. - Flag Parsing Using the provided args (os.Args if empty) - Validate() Validate Config Units. Exit on first error. PreRunner phase (serially, in order of Unit registration) - PreRun() Execute PreRunner Units. Exit on first error. Service phase (concurrently) - Serve() Execute all Service Units in separate Go routines. - Wait Block until one of the Serve() methods returns - GracefulStop() Call interrupt handlers of all Service Units. Run will return with the originating error on: - first Config.Validate() returning an error - first PreRunner.PreRun() returning an error - first Service.Serve() returning (error or nil)
func (*Group) RunConfig ¶
RunConfig runs the Config phase of all registered Config aware Units. Only use this function if needing to add additional wiring between config and (pre)run phases and a separate PreRunner phase is not an option. In most cases it is best to use the Run method directly as it will run the Config phase prior to executing the PreRunner and Service phases. If an error is returned the application must shut down as it is considered fatal.
func (*Group) WaitTillReady ¶
func (g *Group) WaitTillReady()
type PreRunner ¶
PreRunner interface should be implemented by Group Unit objects that need a pre run stage before starting the Group Services. If a Unit's PreRun returns an error it will stop the Group immediately.
func NewPreRunner ¶
NewPreRunner takes a name and a standalone pre runner compatible function and turns them into a Group compatible PreRunner, ready for registration.
type Service ¶
type Service interface { // Unit for Group registration and identification Unit // Serve starts the GroupService and blocks. Serve() StopNotify // GracefulStop shuts down and cleans up the GroupService. GracefulStop() }
Service interface should be implemented by Group Unit objects that need to run a blocking service until an error occurs or a shutdown request is made. The Serve method must be blocking and return an error on unexpected shutdown. Recoverable errors need to be handled inside the service itself. GracefulStop must gracefully stop the service and make the Serve call return.
Since Service is managed by Group, it is considered a design flaw to call any of the Service methods directly in application code.
type StopNotify ¶
type StopNotify <-chan struct{}
type Tester ¶
type Tester struct { ID string // contains filtered or unexported fields }
func (*Tester) GracefulStop ¶
func (t *Tester) GracefulStop()
func (*Tester) Serve ¶
func (t *Tester) Serve() StopNotify