Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyRunning = fmt.Errorf("already running") ErrNotRunning = fmt.Errorf("not running") )
Functions ¶
Types ¶
type Adapter ¶ added in v0.1.0
Adapter wraps a RunFunc with cross-cutting behavior, mirroring the chi middleware shape. Concrete adapters live in runnable/adapters.
type DrainStartedEvent ¶ added in v0.1.0
DrainStartedEvent is published by adapters.Draining when the outer ctx is cancelled and the drain window begins.
type DrainTimedOutEvent ¶ added in v0.1.0
type DrainTimedOutEvent struct{}
DrainTimedOutEvent is published by adapters.Draining when the drain window expires and work is force-cancelled.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func WithAdapters ¶ added in v0.1.0
WithAdapters wraps the runnable's runFunc left-to-right (first listed = outermost). Apply order across Options matters.
func WithPublisher ¶ added in v0.1.0
WithPublisher installs p as the runnable's event Publisher. Stacks additively across calls (and with WithStatus).
func WithStatus ¶ added in v0.0.2
func WithStatus(id string, store *StatusStore) Option
type PanicRecoveredEvent ¶ added in v0.1.0
PanicRecoveredEvent is published by adapters.Recovering when it catches a panic from the wrapped work.
type Publisher ¶ added in v0.1.0
type Publisher interface {
Publish(event any)
}
Publisher receives events from adapters. Implementations must not block — buffer internally if async dispatch is needed.
func PublisherFrom ¶ added in v0.1.0
PublisherFrom returns the Publisher installed in ctx, or nil. Adapters should prefer Publish, which no-ops when none is set.
type Publishers ¶ added in v0.1.0
type Publishers []Publisher
Publishers fans out each event to every member in order; nil members are skipped.
func (Publishers) Publish ¶ added in v0.1.0
func (ps Publishers) Publish(event any)
type RetryEvent ¶ added in v0.1.0
RetryEvent is published by adapters.Retry after a failed attempt (before sleeping or retrying). Attempt is 1-indexed.
type Runnable ¶
type Runnable interface {
Run(ctx context.Context) error
Stop(ctx context.Context) error
IsRunning() bool
}
func New ¶
New creates a new Runnable with the given runFunc.
Example:
type Monitor struct {
runnable.Runnable
}
func (m *Monitor) run(ctx context.Context) error {
// do something
return nil
}
func NewMonitor() Monitor {
m := Monitor{}
m.Runnable = runnable.NewRunnable(m.run)
return m
}
func NewGroup ¶
NewGroup creates a new Runnable that runs multiple runnables concurrently.
Example:
group := NewGroup(
New(func(ctx context.Context) error {
// do something
return nil
}),
New(func(ctx context.Context) error {
// do something
return nil
}),
)
err := group.Run(context.Background())
if err != nil {
// handle error
}
type StatusStore ¶ added in v0.0.2
type StatusStore struct {
// contains filtered or unexported fields
}
func NewStatusStore ¶ added in v0.0.2
func NewStatusStore() *StatusStore
func (*StatusStore) Get ¶ added in v0.0.2
func (s *StatusStore) Get() StatusMap
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package adapters provides chi-style middleware around the runnable RunFunc signature.
|
Package adapters provides chi-style middleware around the runnable RunFunc signature. |
|
ticker-with-drain
command
Example: a periodic reconciler that drains gracefully on SIGTERM.
|
Example: a periodic reconciler that drains gracefully on SIGTERM. |