events

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package events provides real-time event streaming for task lifecycle events

Package events provides real-time event streaming for task lifecycle events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatEvent

func FormatEvent(event *Event) ([]byte, error)

FormatEvent formats an event for JSONL output

func FormatEventCompact

func FormatEventCompact(event *Event) string

FormatEventCompact formats an event in a compact human-readable format

Types

type Bus

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

Bus manages event streaming and subscription

func NewBus

func NewBus() *Bus

NewBus creates a new event bus

func (*Bus) Close

func (b *Bus) Close() error

Close shuts down the event bus

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, event *Event) error

Publish emits an event to all subscribers

func (*Bus) Subscribe

func (b *Bus) Subscribe(name string) chan *Event

Subscribe creates a new subscription channel for events

func (*Bus) SubscriberCount

func (b *Bus) SubscriberCount() int

SubscriberCount returns the number of active subscribers

func (*Bus) Unsubscribe

func (b *Bus) Unsubscribe(ch chan *Event)

Unsubscribe removes a subscription channel

type Event

type Event struct {
	ID        string         `json:"id" db:"id"`
	Type      EventType      `json:"type" db:"type"`
	Timestamp int64          `json:"timestamp" db:"timestamp"`
	TaskID    string         `json:"task_id" db:"task_id"`
	EpicID    string         `json:"epic_id,omitempty" db:"epic_id"`
	Data      map[string]any `json:"data,omitempty" db:"data"` // JSON encoded
}

Event represents a single task lifecycle event

func NewEvent

func NewEvent(eventType EventType, taskID, epicID string, data map[string]any) *Event

NewEvent creates a new event with the current timestamp

func (*Event) MarshalData

func (e *Event) MarshalData() ([]byte, error)

MarshalData converts the Data map to JSON for storage

func (*Event) UnmarshalData

func (e *Event) UnmarshalData(b []byte) error

UnmarshalData parses JSON data into the Data map

type EventFilter

type EventFilter struct {
	Types  []EventType `json:"types,omitempty"`
	EpicID string      `json:"epic_id,omitempty"`
	TaskID string      `json:"task_id,omitempty"`
	Since  int64       `json:"since,omitempty"`  // Unix timestamp
	Until  int64       `json:"until,omitempty"`  // Unix timestamp
	Limit  int         `json:"limit,omitempty"`  // Max events to return
	Follow bool        `json:"follow,omitempty"` // Whether to follow new events (streaming mode)
}

EventFilter defines filters for querying events

type EventType

type EventType string

EventType represents the type of event

const (
	// EventTaskStarted is emitted when a task begins execution
	EventTaskStarted EventType = "task.started"
	// EventTaskCompleted is emitted when a task completes successfully
	EventTaskCompleted EventType = "task.completed"
	// EventTaskFailed is emitted when a task fails
	EventTaskFailed EventType = "task.failed"
	// EventTaskBlocked is emitted when a task is blocked by dependencies
	EventTaskBlocked EventType = "task.blocked"
	// EventTaskUnblocked is emitted when a blocked task's dependencies are resolved
	EventTaskUnblocked EventType = "task.unblocked"
	// EventTaskCancelled is emitted when a task is cancelled
	EventTaskCancelled EventType = "task.cancelled"
	// EventTaskClaimed is emitted when a worker claims a task
	EventTaskClaimed EventType = "task.claimed"
	// EventTaskPaused is emitted when a task is paused
	EventTaskPaused EventType = "task.paused"
	// EventTaskResumed is emitted when a paused task is resumed
	EventTaskResumed EventType = "task.resumed"
)

type StreamOptions

type StreamOptions struct {
	Filter    EventFilter
	JSONLines bool // Output in JSONL format (one JSON object per line)
	Quiet     bool // Suppress non-event messages
}

StreamOptions configures the event stream

type Streamer

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

Streamer handles streaming events to clients

func NewStreamer

func NewStreamer(bus *Bus, filter EventFilter) *Streamer

NewStreamer creates a new event streamer with the given filter

func (*Streamer) Start

func (s *Streamer) Start(ctx context.Context) (<-chan *Event, error)

Start begins streaming events to the returned channel

func (*Streamer) Stop

func (s *Streamer) Stop() error

Stop stops the streamer

Jump to

Keyboard shortcuts

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