events

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// BufferSize controls the per-subscriber channel size.
	BufferSize int
	// HistorySize bounds the number of events retained for resumption.
	HistorySize int
	// JobCacheSize bounds the in-memory job context cache used for log enrichment.
	// Zero applies the default size.
	JobCacheSize int
	// Logger for service diagnostics (optional).
	Logger *slog.Logger
	// Store for database persistence (optional; if nil, persistence methods will fail).
	Store store.Store
}

Options configures the events service.

type Service

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

Service wraps the logstream hub for server-side event streaming and coordinates database persistence with SSE fanout.

func NewService

func NewService(opts Options) (*Service, error)

NewService constructs a new events service.

func (*Service) CreateAndPublishEvent

func (s *Service) CreateAndPublishEvent(ctx context.Context, params store.CreateEventParams) (store.Event, error)

CreateAndPublishEvent persists an event to the database and publishes it to the SSE hub. The runID is used as the streamID for SSE fanout. Returns the created event from the database. If persistence fails, an error is returned; SSE fanout errors are logged but do not fail the operation.

params.RunID is a KSUID-backed RunID; normalized for hub operations.

func (*Service) CreateAndPublishLog

func (s *Service) CreateAndPublishLog(ctx context.Context, log store.Log, data []byte) error

CreateAndPublishLog publishes a log to the job-scoped SSE stream. The log metadata must already be persisted via blobpersist; this method only handles SSE fanout. Log data is decoded into per-line stdout LogRecord frames and published to the job stream keyed by JobID.

If the log has no JobID, SSE fanout is skipped (job-stream requires a job key).

func (*Service) Hub

func (s *Service) Hub() *logstream.Hub

Hub returns the underlying logstream hub.

func (*Service) PublishJobDone

func (s *Service) PublishJobDone(ctx context.Context, jobID domaintypes.JobID, status string) error

PublishJobDone emits a terminal done sentinel on the job-keyed stream, signaling to SSE clients that the job has completed and the stream will close. Returns ErrInvalidJobID if the job ID is blank.

func (*Service) PublishJobRetention

func (s *Service) PublishJobRetention(ctx context.Context, jobID domaintypes.JobID, hint logstream.RetentionHint) error

PublishJobRetention emits a retention hint on the job-keyed stream, informing SSE clients about log retention metadata for the job. Returns ErrInvalidJobID if the job ID is blank.

func (*Service) PublishRun

func (s *Service) PublishRun(ctx context.Context, runID domaintypes.RunID, payload migsapi.RunSummary) error

PublishRun publishes a run lifecycle event (queued/running/succeeded/failed/cancelled) to the SSE hub. The runID (KSUID-backed RunID) is used as the streamID for SSE fanout.

The payload is intentionally typed as migsapi.RunSummary to enforce a JSON-serializable contract at the service boundary and prevent accidental non-JSON payloads from being published. Callers should also emit a terminal "done" status via Hub().PublishStatus when the run reaches a terminal state so SSE clients can terminate streams cleanly. Returns an error if the fanout fails.

Jump to

Keyboard shortcuts

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