Documentation
¶
Index ¶
- func AllServicesEnterState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
- func AllServicesStates(sc *ServiceContext) (<-chan States, context.CancelFunc)
- func AnyServicesEnterState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
- func AnyServicesExitState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
- func NewDaemon(conf DaemonConfig) *daemon
- func NewServiceOpts(options ...ServiceOption) *serviceOpts
- type DaemonConfig
- type RunPolicy
- type Service
- type ServiceContext
- type ServiceOption
- type ServiceResponse
- type State
- type StateUpdate
- type States
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllServicesEnterState ¶ added in v1.1.0
func AllServicesEnterState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
func AllServicesStates ¶ added in v1.0.0
func AllServicesStates(sc *ServiceContext) (<-chan States, context.CancelFunc)
func AnyServicesEnterState ¶ added in v1.1.0
func AnyServicesEnterState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
func AnyServicesExitState ¶ added in v1.0.0
func AnyServicesExitState(sc *ServiceContext, target State, serviceNames ...string) (<-chan States, context.CancelFunc)
AnyServicesExitState
func NewDaemon ¶
func NewDaemon(conf DaemonConfig) *daemon
NewDaemon creates and return an instance of the reactive daemon
func NewServiceOpts ¶
func NewServiceOpts(options ...ServiceOption) *serviceOpts
NewServiceOpts will apply all options in the order given and return the final options back.
Types ¶
type DaemonConfig ¶ added in v1.1.0
type DaemonConfig struct {
Name string // name of the daemon will be used in logging
Signals []os.Signal // OS signals you want your daemon to listen for
LogHandler slog.Handler // log handler for daemon/manager/services
IntracomLogHandler slog.Handler // log handler for embedded intracom instances (debugging)
}
type RunPolicy ¶
type RunPolicy int
RunPolicy service option type representing the run policy of a given service basically controlling different ways of stopping a service like running only once when it succeeds without an error on Run
const ( // RunUntilStoppedPolicy will continue to run the service until a StopState is returned at some point RunUntilStoppedPolicy RunPolicy = iota // RetryUntilSuccessPolicy will continue to re-run the service as long fails happen, use for running a service once successfully RetryUntilSuccessPolicy // RunOncePolicy will only allow the a single Run to take place regardless of success/failure RunOncePolicy )
type Service ¶
type Service interface {
Init(*ServiceContext) ServiceResponse
Idle(*ServiceContext) ServiceResponse
Run(*ServiceContext) ServiceResponse
Stop(*ServiceContext) ServiceResponse
}
type ServiceContext ¶
type ServiceContext struct {
Name string
Log *slog.Logger
ShutdownCtx context.Context
// contains filtered or unexported fields
}
ServiceContext all services will require a config as a *ServiceContext in their service struct. This config contains preconfigured shutdown channel,
func NewService ¶
func NewService(name string, service Service, opts *serviceOpts) *ServiceContext
NewServiceContext creates a new service context instance given a name, service, and service options.
type ServiceOption ¶
type ServiceOption func(*serviceOpts)
ServiceOption are simply using an Option pattern to customize options such as restart policies, timeouts for a given service and how it should run.
func UsingContext ¶ added in v1.1.2
func UsingContext(parent context.Context) ServiceOption
UsingContext creates a new context using the given context as its parent context
func UsingLogHandler ¶ added in v1.1.2
func UsingLogHandler(h slog.Handler) ServiceOption
UsingLogHandler applies a given slog Handler to the underlying service options
func UsingRunPolicy ¶
func UsingRunPolicy(policy RunPolicy) ServiceOption
UsingRunPolicy applies a given policy to the ServiceOption instance
type ServiceResponse ¶
ServiceResponse is used as a return response for services to use so the Manager can determine the "next state" based on return and any error that needs to be broadcasted up the logging channel
func NewResponse ¶
func NewResponse(err error, nextState State) ServiceResponse
NewResponse will create a new ServiceResponse given an error and next state.
type State ¶
type State int
State is used to determine the "next state" the service should enter when the current state has completed/errored returned. State should reflect different states that the interface can enter.
const ( // InitState is in the ServiceResponse to inform manager to move us to the Init state (Initial Default). InitState State = iota // IdleState is in the ServiceResponse to inform manager to move us to the Idle state IdleState // RunState is in the ServiceResponse to inform manager to move us to the Run state RunState // StopState is in the ServiceResponse to inform manager to move us to the Stop state StopState // ExitState is in the ServiceResponse to inform manager to act as the final response type for Stop. ExitState )
type StateUpdate ¶ added in v1.0.0
StateUpdate reflects any given update of lifecycle state at a given time.