Documentation
¶
Overview ¶
Package event provides the event bus abstraction for lifecycle hooks and asynchronous communication between ctrlplane subsystems. It defines event types, the Bus interface, and handler registration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus interface {
// Publish sends an event to all matching subscribers.
Publish(ctx context.Context, event *Event) error
// Subscribe registers a handler for the given event types.
// If no types are specified, the handler receives all events.
Subscribe(handler Handler, types ...Type) Subscription
// Close shuts down the event bus and releases resources.
Close() error
}
Bus is the interface for publishing and subscribing to events.
type Event ¶
type Event struct {
ID id.ID `json:"id"`
Type Type `json:"type"`
TenantID string `json:"tenant_id"`
InstanceID id.ID `json:"instance_id,omitzero"`
ActorID string `json:"actor_id,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
Event is the envelope for all ctrlplane events.
func (*Event) WithInstance ¶
WithInstance sets the instance ID on the event.
type InMemoryBus ¶
type InMemoryBus struct {
// contains filtered or unexported fields
}
InMemoryBus is a channel-based event bus for single-process use and testing.
func NewInMemoryBus ¶
func NewInMemoryBus() *InMemoryBus
NewInMemoryBus creates a new in-memory event bus.
func (*InMemoryBus) Close ¶
func (b *InMemoryBus) Close() error
Close is a no-op for the in-memory bus.
func (*InMemoryBus) Publish ¶
func (b *InMemoryBus) Publish(ctx context.Context, evt *Event) error
Publish sends an event to all matching subscribers synchronously.
func (*InMemoryBus) Subscribe ¶
func (b *InMemoryBus) Subscribe(handler Handler, types ...Type) Subscription
Subscribe registers a handler for the given event types. If no types are specified, the handler receives all events.
type Subscription ¶
type Subscription interface {
// Unsubscribe removes this subscription.
Unsubscribe()
}
Subscription represents an active event subscription.
type Type ¶
type Type string
Type identifies the kind of event.
const ( InstanceCreated Type = "instance.created" InstanceStarted Type = "instance.started" InstanceStopped Type = "instance.stopped" InstanceFailed Type = "instance.failed" InstanceDeleted Type = "instance.deleted" InstanceScaled Type = "instance.scaled" InstanceSuspended Type = "instance.suspended" InstanceUnsuspended Type = "instance.unsuspended" )
Instance events.
const ( DeployStarted Type = "deploy.started" DeploySucceeded Type = "deploy.succeeded" DeployFailed Type = "deploy.failed" DeployRolledBack Type = "deploy.rolled_back" )
Deploy events.
const ( HealthCheckPassed Type = "health.passed" HealthCheckFailed Type = "health.failed" HealthDegraded Type = "health.degraded" HealthRecovered Type = "health.recovered" )
Health events.
type Webhook ¶
type Webhook struct {
ctrlplane.Entity
TenantID string `db:"tenant_id" json:"tenant_id"`
URL string `db:"url" json:"url"`
Secret string `db:"secret" json:"-"`
Events []Type `db:"events" json:"events"`
Active bool `db:"active" json:"active"`
}
Webhook registers an external endpoint for event delivery.
type WebhookDelivery ¶
type WebhookDelivery struct {
ctrlplane.Entity
WebhookID id.ID `db:"webhook_id" json:"webhook_id"`
EventID id.ID `db:"event_id" json:"event_id"`
StatusCode int `db:"status_code" json:"status_code"`
Attempts int `db:"attempts" json:"attempts"`
NextRetry *time.Time `db:"next_retry" json:"next_retry,omitempty"`
Error string `db:"error" json:"error,omitempty"`
}
WebhookDelivery tracks delivery attempts for an event to a webhook.