events

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthTokenChecker

type AuthTokenChecker func(tokenStr string) *jwt.Token

AuthTokenChecker is a function that validates an authorization token.

type Bus

type Bus interface {
	Start(ctx context.Context) error
	Stop() error
	Publish(event *Event)
	Subscribe(filter FilterFunc) *Subscriber
	Unsubscribe(sub *Subscriber)
}

Bus is the interface for the event bus.

type ClientHeadUpdateData

type ClientHeadUpdateData struct {
	ClientIndex  int    `json:"clientIndex"`
	ClientName   string `json:"clientName"`
	CLHeadSlot   uint64 `json:"clHeadSlot"`
	CLHeadRoot   string `json:"clHeadRoot"`
	ELHeadNumber uint64 `json:"elHeadNumber"`
	ELHeadHash   string `json:"elHeadHash"`
}

ClientHeadUpdateData contains data for client.head_update events.

type ClientStatusUpdateData

type ClientStatusUpdateData struct {
	ClientIndex int    `json:"clientIndex"`
	ClientName  string `json:"clientName"`
	CLStatus    string `json:"clStatus"`
	CLReady     bool   `json:"clReady"`
	ELStatus    string `json:"elStatus"`
	ELReady     bool   `json:"elReady"`
}

ClientStatusUpdateData contains data for client.status_update events.

type Event

type Event struct {
	ID        uint64          `json:"id"`
	Type      EventType       `json:"type"`
	Timestamp time.Time       `json:"timestamp"`
	TestRunID uint64          `json:"testRunId,omitempty"`
	TaskIndex uint64          `json:"taskIndex,omitempty"`
	Data      json.RawMessage `json:"data,omitempty"`
}

Event represents a single event in the system.

func NewCustomEvent

func NewCustomEvent(eventType string, testRunID, taskIndex uint64, data any) (*Event, error)

NewCustomEvent creates a new event with a custom event type string.

func NewEvent

func NewEvent(eventType EventType, testRunID, taskIndex uint64, data any) (*Event, error)

NewEvent creates a new event with the given type and data.

type EventBus

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

EventBus is the default implementation of the Bus interface.

func NewEventBus

func NewEventBus(logger logrus.FieldLogger) *EventBus

NewEventBus creates a new event bus.

func (*EventBus) NewCustomEvent

func (eb *EventBus) NewCustomEvent(eventType string, testRunID, taskIndex uint64, data any) (*Event, error)

NewCustomEvent creates a new event with a custom event type string.

func (*EventBus) Publish

func (eb *EventBus) Publish(event *Event)

Publish publishes an event to all subscribers.

func (*EventBus) PublishClientHeadUpdate

func (eb *EventBus) PublishClientHeadUpdate(
	clientIndex int,
	clientName string,
	clHeadSlot uint64,
	clHeadRoot string,
	elHeadNumber uint64,
	elHeadHash string,
)

PublishClientHeadUpdate publishes a client head update event.

func (*EventBus) PublishClientStatusUpdate

func (eb *EventBus) PublishClientStatusUpdate(
	clientIndex int,
	clientName string,
	clStatus string,
	clReady bool,
	elStatus string,
	elReady bool,
)

PublishClientStatusUpdate publishes a client status update event.

func (*EventBus) PublishTaskCompleted

func (eb *EventBus) PublishTaskCompleted(
	testRunID, taskIndex uint64,
	taskName, taskTitle, taskID, result string,
)

PublishTaskCompleted publishes a task completed event.

func (*EventBus) PublishTaskCreated

func (eb *EventBus) PublishTaskCreated(
	testRunID, taskIndex uint64,
	taskName, taskTitle, taskID string,
	parentIndex uint64,
	runConcurrent bool,
)

PublishTaskCreated publishes a task created event.

func (*EventBus) PublishTaskFailed

func (eb *EventBus) PublishTaskFailed(
	testRunID, taskIndex uint64,
	taskName, taskTitle, taskID, errMsg string,
)

PublishTaskFailed publishes a task failed event.

func (*EventBus) PublishTaskLog

func (eb *EventBus) PublishTaskLog(
	testRunID, taskIndex uint64,
	taskName, taskID, level, message string,
	fields map[string]any,
)

PublishTaskLog publishes a task log event.

func (*EventBus) PublishTaskProgress

func (eb *EventBus) PublishTaskProgress(
	testRunID, taskIndex uint64,
	taskName, taskTitle, taskID string,
	progress float64,
	message string,
)

PublishTaskProgress publishes a task progress event.

func (*EventBus) PublishTaskStarted

func (eb *EventBus) PublishTaskStarted(
	testRunID, taskIndex uint64,
	taskName, taskTitle, taskID string,
)

PublishTaskStarted publishes a task started event.

func (*EventBus) PublishTestCompleted

func (eb *EventBus) PublishTestCompleted(testRunID uint64, testID, testName, status string)

PublishTestCompleted publishes a test completed event.

func (*EventBus) PublishTestFailed

func (eb *EventBus) PublishTestFailed(testRunID uint64, testID, testName, errMsg string)

PublishTestFailed publishes a test failed event.

func (*EventBus) PublishTestStarted

func (eb *EventBus) PublishTestStarted(testRunID uint64, testID, testName string)

PublishTestStarted publishes a test started event.

func (*EventBus) Start

func (eb *EventBus) Start(ctx context.Context) error

Start starts the event bus processing loop.

func (*EventBus) Stop

func (eb *EventBus) Stop() error

Stop stops the event bus.

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(filter FilterFunc) *Subscriber

Subscribe creates a new subscription with an optional filter.

func (*EventBus) Unsubscribe

func (eb *EventBus) Unsubscribe(sub *Subscriber)

Unsubscribe removes a subscriber from the event bus.

type EventType

type EventType string

EventType represents the type of event being published.

const (
	EventTestStarted   EventType = "test.started"
	EventTestCompleted EventType = "test.completed"
	EventTestFailed    EventType = "test.failed"
)

Event types for test lifecycle.

const (
	EventTaskCreated   EventType = "task.created"
	EventTaskStarted   EventType = "task.started"
	EventTaskProgress  EventType = "task.progress"
	EventTaskCompleted EventType = "task.completed"
	EventTaskFailed    EventType = "task.failed"
	EventTaskLog       EventType = "task.log"
)

Event types for task lifecycle.

const (
	EventClientHeadUpdate   EventType = "client.head_update"
	EventClientStatusUpdate EventType = "client.status_update"
)

Event types for client updates.

type FilterFunc

type FilterFunc func(*Event) bool

FilterFunc is a function that filters events for a subscriber.

func CombineFilters

func CombineFilters(filters ...FilterFunc) FilterFunc

CombineFilters combines multiple filters with AND logic.

func CreateEventTypeFilter

func CreateEventTypeFilter(eventTypes ...EventType) FilterFunc

CreateEventTypeFilter creates a filter for specific event types.

func CreateTestRunFilter

func CreateTestRunFilter(testRunID uint64) FilterFunc

CreateTestRunFilter creates a filter for a specific test run.

type SSEHandler

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

SSEHandler handles Server-Sent Events connections.

func NewSSEHandler

func NewSSEHandler(logger logrus.FieldLogger, eventBus *EventBus) *SSEHandler

NewSSEHandler creates a new SSE handler.

func NewSSEHandlerWithAuth

func NewSSEHandlerWithAuth(logger logrus.FieldLogger, eventBus *EventBus, authChecker AuthTokenChecker, requireAuthLog bool) *SSEHandler

NewSSEHandlerWithAuth creates a new SSE handler with authentication support.

func (*SSEHandler) HandleClientStream

func (h *SSEHandler) HandleClientStream(w http.ResponseWriter, r *http.Request)

HandleClientStream handles the client events stream endpoint.

func (*SSEHandler) HandleGlobalStream

func (h *SSEHandler) HandleGlobalStream(w http.ResponseWriter, r *http.Request)

HandleGlobalStream handles the global event stream endpoint.

func (*SSEHandler) HandleTestRunStream

func (h *SSEHandler) HandleTestRunStream(w http.ResponseWriter, r *http.Request, testRunID uint64)

HandleTestRunStream handles the per-test event stream endpoint.

type SSEMiddleware

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

SSEMiddleware wraps an SSE handler with common functionality.

func NewSSEMiddleware

func NewSSEMiddleware(logger logrus.FieldLogger, eventBus *EventBus) *SSEMiddleware

NewSSEMiddleware creates a new SSE middleware.

func (*SSEMiddleware) GlobalStreamHandler

func (m *SSEMiddleware) GlobalStreamHandler() http.HandlerFunc

GlobalStreamHandler returns an http.HandlerFunc for the global event stream.

func (*SSEMiddleware) TestRunStreamHandler

func (m *SSEMiddleware) TestRunStreamHandler(testRunID uint64) http.HandlerFunc

TestRunStreamHandler returns a function that creates handlers for test run streams.

type Subscriber

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

Subscriber represents a subscriber to the event bus.

func (*Subscriber) Channel

func (s *Subscriber) Channel() <-chan *Event

Channel returns the channel for receiving events.

type TaskCompletedData

type TaskCompletedData struct {
	TaskName  string `json:"taskName"`
	TaskTitle string `json:"taskTitle"`
	TaskID    string `json:"taskId,omitempty"`
	Result    string `json:"result"`
}

TaskCompletedData contains data for task.completed events.

type TaskCreatedData

type TaskCreatedData struct {
	TaskName      string `json:"taskName"`
	TaskTitle     string `json:"taskTitle"`
	TaskID        string `json:"taskId,omitempty"`
	ParentIndex   uint64 `json:"parentIndex"`
	RunConcurrent bool   `json:"runConcurrent,omitempty"`
}

TaskCreatedData contains data for task.created events.

type TaskFailedData

type TaskFailedData struct {
	TaskName  string `json:"taskName"`
	TaskTitle string `json:"taskTitle"`
	TaskID    string `json:"taskId,omitempty"`
	Error     string `json:"error,omitempty"`
}

TaskFailedData contains data for task.failed events.

type TaskLogData

type TaskLogData struct {
	TaskName  string         `json:"taskName"`
	TaskID    string         `json:"taskId,omitempty"`
	Level     string         `json:"level"`
	Message   string         `json:"message"`
	Fields    map[string]any `json:"fields,omitempty"`
	Timestamp time.Time      `json:"timestamp"`
}

TaskLogData contains data for task.log events.

type TaskProgressData

type TaskProgressData struct {
	TaskName  string  `json:"taskName"`
	TaskTitle string  `json:"taskTitle"`
	TaskID    string  `json:"taskId,omitempty"`
	Progress  float64 `json:"progress"`
	Message   string  `json:"message,omitempty"`
}

TaskProgressData contains data for task.progress events.

type TaskStartedData

type TaskStartedData struct {
	TaskName  string `json:"taskName"`
	TaskTitle string `json:"taskTitle"`
	TaskID    string `json:"taskId,omitempty"`
}

TaskStartedData contains data for task.started events.

type TestCompletedData

type TestCompletedData struct {
	TestID   string `json:"testId"`
	TestName string `json:"testName"`
	Status   string `json:"status"`
}

TestCompletedData contains data for test.completed events.

type TestFailedData

type TestFailedData struct {
	TestID   string `json:"testId"`
	TestName string `json:"testName"`
	Error    string `json:"error,omitempty"`
}

TestFailedData contains data for test.failed events.

type TestStartedData

type TestStartedData struct {
	TestID   string `json:"testId"`
	TestName string `json:"testName"`
}

TestStartedData contains data for test.started events.

Jump to

Keyboard shortcuts

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