Documentation
¶
Index ¶
- type Options
- type Service
- func (s *Service) CreateAndPublishEvent(ctx context.Context, params store.CreateEventParams) (store.Event, error)
- func (s *Service) CreateAndPublishLog(ctx context.Context, log store.Log, data []byte) error
- func (s *Service) Hub() *logstream.Hub
- func (s *Service) PublishJobDone(ctx context.Context, jobID domaintypes.JobID, status string) error
- func (s *Service) PublishJobRetention(ctx context.Context, jobID domaintypes.JobID, hint logstream.RetentionHint) error
- func (s *Service) PublishRun(ctx context.Context, runID domaintypes.RunID, payload migsapi.RunSummary) error
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 ¶
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 ¶
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) PublishJobDone ¶
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.