events

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID        string                 `json:"id"`
	Type      EventType              `json:"type"`
	Timestamp time.Time              `json:"timestamp"`
	Source    string                 `json:"source"`
	Data      map[string]interface{} `json:"data"`
	Tags      map[string]string      `json:"tags,omitempty"`
}

Event represents a system event

func NewEvent

func NewEvent(eventType EventType, source string, data map[string]interface{}) *Event

NewEvent creates a new event with a unique ID

type EventBus

type EventBus struct {
	// contains filtered or unexported fields
}

EventBus manages event publishing and subscription

func NewEventBus

func NewEventBus(bufferSize, workers int) *EventBus

NewEventBus creates a new event bus

func (*EventBus) Close

func (b *EventBus) Close() error

Close shuts down the event bus

func (*EventBus) Publish

func (b *EventBus) Publish(event *Event) error

Publish publishes an event to the bus

func (*EventBus) PublishSync

func (b *EventBus) PublishSync(ctx context.Context, event *Event) error

PublishSync publishes an event synchronously

func (*EventBus) Subscribe

func (b *EventBus) Subscribe(handler EventHandler)

Subscribe subscribes a handler to specific event types

func (*EventBus) Unsubscribe

func (b *EventBus) Unsubscribe(handler EventHandler)

Unsubscribe removes a handler from all event types

type EventEmitter

type EventEmitter struct {
	// contains filtered or unexported fields
}

EventEmitter helps emit events during operations

func NewEventEmitter

func NewEventEmitter(bus *EventBus, source string) *EventEmitter

NewEventEmitter creates a new event emitter

func (*EventEmitter) EmitApplyCompleted

func (e *EventEmitter) EmitApplyCompleted(moduleName string, summary map[string]int, duration time.Duration) error

EmitApplyCompleted emits an apply completed event

func (*EventEmitter) EmitApplyStarted

func (e *EventEmitter) EmitApplyStarted(moduleName string, resourceCount int) error

EmitApplyStarted emits an apply started event

func (*EventEmitter) EmitDriftDetected

func (e *EventEmitter) EmitDriftDetected(moduleName string, resourceID string, changes map[string]interface{}) error

EmitDriftDetected emits a drift detected event

func (*EventEmitter) EmitPlanCompleted

func (e *EventEmitter) EmitPlanCompleted(moduleName string, summary map[string]int, duration time.Duration) error

EmitPlanCompleted emits a plan completed event

func (*EventEmitter) EmitPlanStarted

func (e *EventEmitter) EmitPlanStarted(moduleName string, resourceCount int) error

EmitPlanStarted emits a plan started event

func (*EventEmitter) EmitResourceCompleted

func (e *EventEmitter) EmitResourceCompleted(resourceID string, action types.DiffAction, duration time.Duration) error

EmitResourceCompleted emits a resource completed event

func (*EventEmitter) EmitResourceFailed

func (e *EventEmitter) EmitResourceFailed(resourceID string, action types.DiffAction, err error, duration time.Duration) error

EmitResourceFailed emits a resource failed event

func (*EventEmitter) EmitResourceStarted

func (e *EventEmitter) EmitResourceStarted(resourceID string, action types.DiffAction) error

EmitResourceStarted emits a resource started event

type EventHandler

type EventHandler interface {
	Handle(ctx context.Context, event *Event) error
	Types() []EventType
	Name() string
}

EventHandler handles events

type EventType

type EventType string

EventType represents the type of event

const (
	EventTypeResourceStarted   EventType = "resource.started"
	EventTypeResourceCompleted EventType = "resource.completed"
	EventTypeResourceFailed    EventType = "resource.failed"
	EventTypeResourceSkipped   EventType = "resource.skipped"
	EventTypePlanStarted       EventType = "plan.started"
	EventTypePlanCompleted     EventType = "plan.completed"
	EventTypePlanFailed        EventType = "plan.failed"
	EventTypeApplyStarted      EventType = "apply.started"
	EventTypeApplyCompleted    EventType = "apply.completed"
	EventTypeApplyFailed       EventType = "apply.failed"
	EventTypeDriftDetected     EventType = "drift.detected"
	EventTypeRollbackStarted   EventType = "rollback.started"
	EventTypeRollbackCompleted EventType = "rollback.completed"
)

type FileEventHandler

type FileEventHandler struct {
	// contains filtered or unexported fields
}

FileEventHandler writes events to a file

func NewFileEventHandler

func NewFileEventHandler(name, filePath string, eventTypes []EventType) *FileEventHandler

NewFileEventHandler creates a new file event handler

func (*FileEventHandler) Handle

func (h *FileEventHandler) Handle(ctx context.Context, event *Event) error

Handle handles an event by writing it to a file

func (*FileEventHandler) Name

func (h *FileEventHandler) Name() string

Name returns the handler name

func (*FileEventHandler) Types

func (h *FileEventHandler) Types() []EventType

Types returns the event types this handler subscribes to

type LogEventHandler

type LogEventHandler struct {
	// contains filtered or unexported fields
}

LogEventHandler logs events to stdout

func NewLogEventHandler

func NewLogEventHandler(name string, eventTypes []EventType, verbose bool) *LogEventHandler

NewLogEventHandler creates a new log event handler

func (*LogEventHandler) Handle

func (h *LogEventHandler) Handle(ctx context.Context, event *Event) error

Handle handles an event by logging it

func (*LogEventHandler) Name

func (h *LogEventHandler) Name() string

Name returns the handler name

func (*LogEventHandler) Types

func (h *LogEventHandler) Types() []EventType

Types returns the event types this handler subscribes to

type MetricsEventHandler

type MetricsEventHandler struct {
	// contains filtered or unexported fields
}

MetricsEventHandler collects metrics from events

func NewMetricsEventHandler

func NewMetricsEventHandler(name string, eventTypes []EventType) *MetricsEventHandler

NewMetricsEventHandler creates a new metrics event handler

func (*MetricsEventHandler) GetMetrics

func (h *MetricsEventHandler) GetMetrics() map[string]int64

GetMetrics returns current metrics

func (*MetricsEventHandler) Handle

func (h *MetricsEventHandler) Handle(ctx context.Context, event *Event) error

Handle handles an event by updating metrics

func (*MetricsEventHandler) Name

func (h *MetricsEventHandler) Name() string

Name returns the handler name

func (*MetricsEventHandler) Types

func (h *MetricsEventHandler) Types() []EventType

Types returns the event types this handler subscribes to

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL