Documentation
¶
Index ¶
- Constants
- func NewDaemon(services ...*ServiceContext) *daemon
- func NewServiceOpts(options ...ServiceOption) *serviceOpts
- type Level
- type LogMessage
- type LogSeverity
- type Logger
- func (l *Logger) Debug(v ...any)
- func (l *Logger) Debugf(format string, v ...any)
- func (l *Logger) Error(v ...any)
- func (l *Logger) Errorf(format string, v ...any)
- func (l *Logger) Info(v ...any)
- func (l *Logger) Infof(format string, v ...any)
- func (l *Logger) Warn(v ...any)
- func (l *Logger) Warnf(format string, v ...any)
- type Logging
- type RunPolicy
- type Service
- type ServiceContext
- func (sc *ServiceContext) AddDependentService(s *ServiceContext, states ...State) error
- func (sc *ServiceContext) ChangeState() chan State
- func (sc *ServiceContext) IntracomPublish(topic string, message []byte)
- func (sc *ServiceContext) IntracomSubscribe(topic string, id string) <-chan []byte
- func (sc *ServiceContext) IntracomUnsubscribe(topic string, id string)
- func (sc *ServiceContext) ShutdownSignal() <-chan struct{}
- type ServiceOption
- type ServiceResponse
- type State
Constants ¶
const (
InternalServiceStates = "_rxd.states"
)
const (
NoFlags = 0
)
Variables ¶
This section is empty.
Functions ¶
func NewDaemon ¶
func NewDaemon(services ...*ServiceContext) *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 LogMessage ¶
func NewLog ¶
func NewLog(message string, level Level) LogMessage
NewLog creates a new instance of a LogMessage from a string and level.
type LogSeverity ¶
type LogSeverity int
LogSeverity is a typed int that represents the severity of the logging levels.
const ( // LevelAll will show all severity levels LevelAll LogSeverity = 0 // LevelDebug will show all severity levels at Debug and above: Debug, Info, Error LevelDebug LogSeverity = 1 // LevelInfo will show all severity levels at Info and above: Info, Error LevelInfo LogSeverity = 2 // LevelWarn will show all severity levels at Warn and above: Warn, Error LevelWarn LogSeverity = 3 // LevelError will show all severity levels at Error and above: Error LevelError LogSeverity = 4 // LevelOff will not show any logs, logging will be off LevelOff LogSeverity = 6 )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(logSeverity LogSeverity, flags int) *Logger
NewLogger returns an instance of Logger with Debug, Info and Error loggers. Each logger is configured with sane defaults. Debug output is set with env var "DEBUG"; defaults to io.Discard
type RunPolicy ¶
type RunPolicy string
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 = "until_stopped" // RetryUntilSuccessPolicy will continue to re-run the service as long fails happen, use for running a service once successfully RetryUntilSuccessPolicy RunPolicy = "retry_until_success" // RunOncePolicy will only allow the a single Run to take place regardless of success/failure RunOncePolicy RunPolicy = "run_once" )
type Service ¶
type Service interface {
Init(*ServiceContext) ServiceResponse
Idle(*ServiceContext) ServiceResponse
Run(*ServiceContext) ServiceResponse
Stop(*ServiceContext) ServiceResponse
}
type ServiceContext ¶
type ServiceContext struct {
Name string
Ctx context.Context
Log Logging
// 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
NewService creates a new service instance given a name and options.
func (*ServiceContext) AddDependentService ¶
func (sc *ServiceContext) AddDependentService(s *ServiceContext, states ...State) error
AddDependentService adds a service that depends on the current service and the states the dependent service is interested in.
func (*ServiceContext) ChangeState ¶
func (sc *ServiceContext) ChangeState() chan State
ChangeState returns the channel the service listens for state changes of the service it depends on defined by UsingServiceNotify option on creation of the ServiceContext.
func (*ServiceContext) IntracomPublish ¶
func (sc *ServiceContext) IntracomPublish(topic string, message []byte)
IntracomPublish will publish the bytes message to the topic, only if there is subscribed interest.
func (*ServiceContext) IntracomSubscribe ¶
func (sc *ServiceContext) IntracomSubscribe(topic string, id string) <-chan []byte
IntracomSubscribe subscribes this service to inter-service communication by its topic name. A channel is returned to receive published messages from another service. Standardized on slice of bytes since it allows us to easily json unmarshal into struct if needed.
func (*ServiceContext) IntracomUnsubscribe ¶
func (sc *ServiceContext) IntracomUnsubscribe(topic string, id string)
IntracomUnsubscribe unsubscribes this service from inter-service communication by its topic name
func (*ServiceContext) ShutdownSignal ¶
func (sc *ServiceContext) ShutdownSignal() <-chan struct{}
ShutdownSignal returns the channel the side implementing the service should use and watch to be notified when the daemon/manager are attempting to shutdown services.
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 UsingDefaultLogger ¶
func UsingDefaultLogger(severity LogSeverity, flags int) ServiceOption
UsingDefaultLogger applies new logging instance as the logger with a customized log severity level and flags to use.
func UsingLogger ¶
func UsingLogger(logger Logging) ServiceOption
UsingLogger applies a given logger that meets the Logging interface to the ServiceOption instance
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 string
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 = "init" // IdleState is in the ServiceResponse to inform manager to move us to the Idle state IdleState State = "idle" // RunState is in the ServiceResponse to inform manager to move us to the Run state RunState State = "run" // StopState is in the ServiceResponse to inform manager to move us to the Stop state StopState State = "stop" // ExitState is in the ServiceResponse to inform manager to act as the final response type for Stop. ExitState State = "exit" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
custom_logger
command
|
|
|
multi_service
command
|
|
|
single_web_service
command
|