Documentation
¶
Index ¶
- Variables
- type Config
- type ConfigCallback
- type Option
- type ReloadableWithConfig
- type RunnableEntry
- type Runner
- func (r *Runner[T]) GetChildStates() map[string]string
- func (r *Runner[T]) GetState() string
- func (r *Runner[T]) GetStateChan(ctx context.Context) <-chan string
- func (r *Runner[T]) IsRunning() bool
- func (r *Runner[T]) Reload()
- func (r *Runner[T]) Run(ctx context.Context) error
- func (r *Runner[T]) Stop()
- func (r *Runner[T]) String() string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCompositeRunnable is returned when there's a general error in the composite runnable ErrCompositeRunnable = errors.New("composite runnable error") // ErrRunnableFailed is returned when a child runnable fails ErrRunnableFailed = errors.New("child runnable failed") // ErrConfigMissing is returned when the config is missing ErrConfigMissing = errors.New("config is missing") // ErrOldConfig is returned when the config hasn't changed during a reload ErrOldConfig = errors.New("configuration unchanged") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[T runnable] struct { // Name is a human-readable identifier for this composite runner Name string // Entries is the list of runnables with their associated configurations Entries []RunnableEntry[T] }
Config represents the configuration for a CompositeRunner
func NewConfig ¶
func NewConfig[T runnable]( name string, entries []RunnableEntry[T], ) (*Config[T], error)
NewConfig creates a new Config instance for a CompositeRunner
func NewConfigFromRunnables ¶
func NewConfigFromRunnables[T runnable]( name string, runnables []T, sharedConfig any, ) (*Config[T], error)
NewConfigFromRunnables creates a Config from a list of runnables, all using the same config
type ConfigCallback ¶
ConfigCallback is the function type signature for the callback used to load initial config, and new config during Reload()
type Option ¶
type Option[T runnable] func(*Runner[T])
Option represents a functional option for configuring CompositeRunner
func WithContext ¶
WithContext sets a custom context for the CompositeRunner instance. This allows for more granular control over cancellation and timeouts.
func WithLogHandler ¶
WithLogHandler sets a custom slog handler for the CompositeRunner instance.
type ReloadableWithConfig ¶
type ReloadableWithConfig interface {
ReloadWithConfig(config any)
}
ReloadableWithConfig is an interface for sub-runnables that can reload with specific config
type RunnableEntry ¶
type RunnableEntry[T runnable] struct { // Runnable is the component to be managed Runnable T // Config holds the configuration data for this specific runnable Config any }
RunnableEntry associates a runnable with its configuration
type Runner ¶
type Runner[T runnable] struct {
// contains filtered or unexported fields
}
Runner implements a component that manages multiple runnables of the same type as a single unit. It satisfies the Runnable, Reloadable, and Stateable interfaces.
func NewRunner ¶
func NewRunner[T runnable]( configCallback ConfigCallback[T], opts ...Option[T], ) (*Runner[T], error)
NewRunner creates a new CompositeRunner instance with the provided configuration callback and options. Parameters:
- configCallback: Required. A function that returns the initial configuration and is called during any reload operations.
- opts: Optional. A variadic list of Option functions to customize the Runner behavior.
The configCallback must not be nil and will be invoked by Run() to load the initial configuration.
func (*Runner[T]) GetChildStates ¶
GetChildStates returns a map of child runnable names to their states.
func (*Runner[T]) GetStateChan ¶
GetStateChan returns a channel that will receive state updates.
func (*Runner[T]) Reload ¶
func (r *Runner[T]) Reload()
Reload updates the configuration and handles runnables appropriately. If membership changes (different set of runnables), all existing runnables are stopped and the new set is started to ensure proper lifecycle management.
func (*Runner[T]) Run ¶
Run starts all child runnables in order (first to last) and monitors for completion or errors. This method blocks until all child runnables are stopped or an error occurs.