Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, opts Options, groups ...ServiceGroup)
Run runs the provided service groups. If more than one service group is passed, it will run groups in the same order as they were provided. Each service group represents a collection of services that are independent. Upon context cancellation, a graceful terminate is initiated; it will start by closing the last service group and then close the group before it. While doing so, it ensures that it begins closing the second group if and only if the group before it gracefully closed (i.e., all services returned). For example, let us say that we have 3 service groups, SG1, SG2, SG3. If we do Run(ctx, logger, SG1, SG2, SG3), it will run the groups in following sequence: SG1 -> SG2 -> SG3. When ctx is cancelled, it will shut down in the following order: SG3 -> SG2 -> SG1. In case any service during runtime panics, it will restart it with the provided RecoverDuration (or default, if not set).
Types ¶
type Options ¶
type Options struct { // RecoverDuration specifies the duration after which a service // will attempt to recover after panic. RecoverDuration time.Duration // BeforeServiceStart is a function that is executed when a service // is about to start. BeforeServiceStart func(name string) // AfterServiceStop is a function that is executed when a service // stops. It is not invoked after a panic. AfterServiceStop func(name string) // AfterServicePanic is a function that is executed when a service // panics. AfterServicePanic func(name string, stack []byte) }
Options specifies additional options that can be provided when running flower.
type Service ¶
type Service interface { // Run should run the service with the provided context and logger. // If context is cancelled, the service should close gracefully. Run(context.Context) }
Service is an interface that represents a service that can be ran as a separate, independent goroutine.
type ServiceFunc ¶
ServiceFunc is a wrapper around a service function that enables it to behave like a Service.
func (ServiceFunc) Run ¶
func (sf ServiceFunc) Run(ctx context.Context)
Run runs the provided service.
type ServiceGroup ¶
ServiceGroup represents a group of services where the key is service name and the value is the service itself.