Documentation
¶
Overview ¶
Package lifecycle provides generic event-driven lifecycle primitives.
It is intentionally separate from policycontroller, which reconciles a desired state synchronously, and eventstream, which carries bounded live command output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SortRecordsByID ¶
SortRecordsByID provides deterministic ordering for store implementations.
Types ¶
type Claim ¶
Claim identifies a leased event and prevents a stale worker from acknowledging or rescheduling a lease it no longer owns.
type Dispatcher ¶
type Dispatcher struct {
Events EventStore
Handler Handler
Clock func() time.Time
LeaseDuration time.Duration
RetryDelay time.Duration
CompactAfter time.Duration
}
Dispatcher publishes and delivers lifecycle events with at-least-once semantics. Handlers must be idempotent because a process can exit after an action succeeds and before its acknowledgement is persisted.
func NewDispatcher ¶
func NewDispatcher(events EventStore, handler Handler) *Dispatcher
NewDispatcher constructs a dispatcher with conservative operational defaults. The queue remains usable without a background goroutine through RunOnce, which keeps integration tests and one-shot tools deterministic.
func (*Dispatcher) Publish ¶
func (d *Dispatcher) Publish(ctx context.Context, event Event) error
Publish appends an event. An existing event with the same ID is treated as an idempotent duplicate when its envelope matches.
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Subject string `json:"subject"`
Payload json.RawMessage `json:"payload,omitempty"`
RecordedAt time.Time `json:"recorded_at"`
AvailableAt time.Time `json:"available_at"`
Attempt int `json:"attempt"`
}
Event is the non-secret envelope persisted in the operational event queue. Payload must contain identifiers and safe state only; callers must not put credentials or other secret material in it.
type EventStore ¶
type EventStore interface {
Append(context.Context, Event) error
Claim(context.Context, time.Time, time.Duration) (Claim, error)
Ack(context.Context, Claim) error
Retry(context.Context, Claim, time.Time, error) error
Fail(context.Context, Claim, error) error
Compact(context.Context, time.Time) error
}
EventStore is the narrow durable queue contract used by Dispatcher.
type HandlerFunc ¶
HandlerFunc adapts a function to Handler.
type Record ¶
type Record struct {
Event Event `json:"event"`
Status Status `json:"status"`
LeaseToken string `json:"lease_token,omitempty"`
LeaseUntil time.Time `json:"lease_until,omitempty"`
LastError string `json:"last_error,omitempty"`
Completed time.Time `json:"completed,omitempty"`
}
Record is the persisted queue representation. EventStore implementations may persist this directly in their native format.