realtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package realtime streams a Rendobar workspace's events as they happen: job progress, logs and status, balance and notification changes.

It is a separate package so its WebSocket dependency is built only into programs that import it. Follow one job to its end:

rt := realtime.New() // reads RENDOBAR_API_KEY
for ev, err := range rt.Job(ctx, jobID) {
	if err != nil {
		return err
	}
	switch e := ev.(type) {
	case *realtime.JobProgress:
		fmt.Println(e.Phase, e.Progress)
	case *realtime.JobStatusChanged:
		fmt.Println("status", e.Status)
	}
}

The stream reconnects on its own and resumes where it left off, so a dropped connection costs no events the workspace keeps for replay.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeysUpdated

type APIKeysUpdated struct {
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

APIKeysUpdated says a key was created, changed or revoked. It carries no key: read APIKeys.List again.

func (APIKeysUpdated) EventID

func (c APIKeysUpdated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*APIKeysUpdated) Type

func (*APIKeysUpdated) Type() string

type BalanceUpdated

type BalanceUpdated struct {
	Balance          int64               `json:"balance"` // nanodollars
	TxnType          string              `json:"txnType"`
	TxnAmount        *int64              `json:"txnAmount"` // nanodollars
	BalanceFormatted string              `json:"balanceFormatted"`
	Timestamp        rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

BalanceUpdated is the workspace's balance changing.

func (BalanceUpdated) EventID

func (c BalanceUpdated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*BalanceUpdated) Type

func (*BalanceUpdated) Type() string

type Client

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

Client opens event streams. Make one with New and reuse it: it is safe for concurrent use.

func New

func New(opts ...Option) *Client

New returns a client. With no WithAPIKey it reads RENDOBAR_API_KEY. A client with no key, or one that does not start with rb_, yields a *rendobar.Error with code MISSING_API_KEY or INVALID_API_KEY from every stream, without connecting.

func (*Client) Events

func (c *Client) Events(ctx context.Context, p EventsParams) iter.Seq2[Event, error]

Events yields every event of the workspace until ctx ends, then the context's error. It yields *Connected on each connection, the replayed events, *ReplayDone, then live events. A dropped connection reconnects with backoff and resumes after the last event yielded, and an event seen before is never yielded twice. Breaking out of the loop closes the connection.

A refusal that no retry fixes, such as a revoked key (401), a key without the jobs:read scope (403) or a malformed key, is yielded as a *rendobar.Error and ends the stream.

func (*Client) Job

func (c *Client) Job(ctx context.Context, id string) iter.Seq2[Event, error]

Job yields one job's events: *Connected, then its progress, steps, logs, resources, previews, status and result, replayed ones first. It leaves out the workspace's other events. It returns after the job reaches a final status, the *JobStatusChanged for it included, so a job that already ended returns after its replayed status. It ends early, with the context's error, when ctx ends. A job the workspace does not have is a NOT_FOUND *rendobar.Error.

type Connected

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

Connected is yielded each time the stream connects, the first time included. Events the workspace kept since LastEventID follow, then ReplayDone.

func (Connected) EventID

func (c Connected) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*Connected) Type

func (*Connected) Type() string

type Event

type Event interface {
	// Type is the event's name on the wire, such as "job.progress".
	Type() string
	// EventID is the stream's cursor for the event, or 0 for an event the
	// workspace does not keep for replay, such as progress. Pass the last one
	// you handled as EventsParams.LastEventID to resume after it.
	EventID() int64
	// contains filtered or unexported methods
}

Event is one message from the stream: a pointer to one of the types in this file, such as *JobProgress or *BalanceUpdated, or *Unknown for a message this SDK cannot read. Read it with a type switch that keeps a default branch.

type EventsParams

type EventsParams struct {
	// LastEventID resumes after the event with this EventID: the workspace
	// replays what it kept since then. 0 replays everything it keeps.
	LastEventID int64
}

EventsParams starts Client.Events.

type JobContext

type JobContext struct {
	JobID     string              `json:"jobId"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	Machine   string              `json:"machine"`
	CPU       *float64            `json:"cpu"`
	Memory    *float64            `json:"memory"`
	Region    string              `json:"region"`
	// contains filtered or unexported fields
}

JobContext is the machine a job runs on.

func (JobContext) EventID

func (c JobContext) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobContext) Type

func (*JobContext) Type() string

type JobCreated

type JobCreated struct {
	JobID   string             `json:"jobId"`
	JobType rendobar.JobType   `json:"jobType"`
	Status  rendobar.JobStatus `json:"status"`
	// contains filtered or unexported fields
}

JobCreated is a job the workspace submitted.

func (JobCreated) EventID

func (c JobCreated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobCreated) Type

func (*JobCreated) Type() string

type JobLog

type JobLog struct {
	JobID      string                     `json:"jobId"`
	Timestamp  rendobar.UnixMillis        `json:"timestamp"`
	Level      LogLevel                   `json:"level"`
	Message    string                     `json:"message"`
	Step       string                     `json:"step"`
	Event      string                     `json:"event"`
	DurationMs *float64                   `json:"durationMs"`
	Meta       map[string]json.RawMessage `json:"meta"` // free-form detail, as JSON
	// contains filtered or unexported fields
}

JobLog is one log line of a running job. Jobs.Logs reads them all later.

func (JobLog) EventID

func (c JobLog) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobLog) Type

func (*JobLog) Type() string

type JobPreview

type JobPreview struct {
	JobID     string              `json:"jobId"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	Seq       int64               `json:"seq"`
	Progress  *float64            `json:"progress"` // 0 to 1, or nil
	Width     int64               `json:"width"`
	Height    int64               `json:"height"`
	Data      string              `json:"data"` // a base64 WebP image, about 256 px on its long edge
	// contains filtered or unexported fields
}

JobPreview is a small frame of an image while it generates. Frames are not replayed, and one with a Seq at or below the last you showed is stale.

func (JobPreview) EventID

func (c JobPreview) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobPreview) Type

func (*JobPreview) Type() string

type JobProgress

type JobProgress struct {
	JobID     string              `json:"jobId"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// Progress is the fraction done, 0 to 1, or nil when it cannot be told.
	Progress *float64 `json:"progress"`
	// Phase is "" from a runner that predates phases.
	Phase        Phase    `json:"phase"`
	Step         string   `json:"step"`
	StepProgress *float64 `json:"stepProgress"`
	// ETA is the seconds left, or nil. It may grow. Progress does not shrink.
	ETA     *float64          `json:"eta"`
	Metrics map[string]Metric `json:"metrics"`
	// contains filtered or unexported fields
}

JobProgress is how far a running job is. Build a progress display on Phase and Progress. Step is the internal step, which varies by job type.

func (JobProgress) EventID

func (c JobProgress) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobProgress) Type

func (*JobProgress) Type() string

type JobRegionFailover

type JobRegionFailover struct {
	JobID      string              `json:"jobId"`
	FromRegion string              `json:"fromRegion"`
	ToRegion   string              `json:"toRegion"`
	Timestamp  rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

JobRegionFailover is a job moved to another region to run.

func (JobRegionFailover) EventID

func (c JobRegionFailover) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobRegionFailover) Type

func (*JobRegionFailover) Type() string

type JobResources

type JobResources struct {
	JobID           string              `json:"jobId"`
	Timestamp       rendobar.UnixMillis `json:"timestamp"`
	CPUPct          *float64            `json:"cpuPct"`
	CPUCores        float64             `json:"cpuCores"`
	AllocatedCores  *float64            `json:"allocatedCores"`
	MemUsedMB       float64             `json:"memUsedMB"`
	MemLimitMB      *float64            `json:"memLimitMB"`
	Threads         *float64            `json:"threads"`
	CPUThrottledPct *float64            `json:"cpuThrottledPct"`
	CPUPressurePct  *float64            `json:"cpuPressurePct"`
	MemPressurePct  *float64            `json:"memPressurePct"`
	IOPressurePct   *float64            `json:"ioPressurePct"`
	DiskUsedMB      *float64            `json:"diskUsedMB"`
	DiskRMBps       *float64            `json:"diskRMBps"`
	DiskWMBps       *float64            `json:"diskWMBps"`
	NetRxMBps       *float64            `json:"netRxMBps"`
	NetTxMBps       *float64            `json:"netTxMBps"`
	GPUPct          *float64            `json:"gpuPct"`
	GPUMemUsedMB    *float64            `json:"gpuMemUsedMB"`
	GPUMemTotalMB   *float64            `json:"gpuMemTotalMB"`
	GPUTempC        *float64            `json:"gpuTempC"`
	GPUPowerW       *float64            `json:"gpuPowerW"`
	GPUEncPct       *float64            `json:"gpuEncPct"`
	GPUDecPct       *float64            `json:"gpuDecPct"`
	GPUMemBwPct     *float64            `json:"gpuMemBwPct"`
	// contains filtered or unexported fields
}

JobResources is one sample of what a running job uses. A value the runner could not measure is nil.

func (JobResources) EventID

func (c JobResources) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobResources) Type

func (*JobResources) Type() string

type JobResult

type JobResult struct {
	JobID string `json:"jobId"`
	// contains filtered or unexported fields
}

JobResult says a job's output is ready. Jobs.Get reads it.

func (JobResult) EventID

func (c JobResult) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobResult) Type

func (*JobResult) Type() string

type JobStatusChanged

type JobStatusChanged struct {
	JobID  string             `json:"jobId"`
	Status rendobar.JobStatus `json:"status"`
	// Error is the failure message, for a failed job.
	Error string `json:"error"`
	// Price is what the job cost in nanodollars, once it ended, or nil.
	Price          *int64 `json:"price"`
	PriceFormatted string `json:"priceFormatted"`
	// contains filtered or unexported fields
}

JobStatusChanged is a job moving to another status.

func (JobStatusChanged) EventID

func (c JobStatusChanged) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobStatusChanged) Final

func (e *JobStatusChanged) Final() bool

Final reports whether the status is one a job ends in: complete, failed or cancelled.

func (*JobStatusChanged) Type

func (*JobStatusChanged) Type() string

type JobStep

type JobStep struct {
	JobID      string              `json:"jobId"`
	Timestamp  rendobar.UnixMillis `json:"timestamp"`
	Step       string              `json:"step"`
	StepName   string              `json:"stepName"`
	Status     rendobar.StepStatus `json:"status"`
	Index      int64               `json:"index"`
	Total      int64               `json:"total"`
	DurationMs *float64            `json:"durationMs"`
	// contains filtered or unexported fields
}

JobStep is a job's internal step starting or ending. It varies by job type, so prefer JobProgress for a display.

func (JobStep) EventID

func (c JobStep) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*JobStep) Type

func (*JobStep) Type() string

type LeaveReason

type LeaveReason string

LeaveReason says why someone is no longer a member. The API may add reasons.

const (
	LeaveRemoved LeaveReason = "removed" // another member removed them
	LeaveSelf    LeaveReason = "left"    // they left on their own
)

The LeaveReason values this SDK knows.

type LogLevel

type LogLevel string

LogLevel is a log entry's level. The API may add levels.

const (
	LogDebug LogLevel = "debug"
	LogInfo  LogLevel = "info"
	LogWarn  LogLevel = "warn"
	LogError LogLevel = "error"
)

The LogLevel values this SDK knows.

type MemberUpdated

type MemberUpdated struct {
	UserID string `json:"userId"`
	// Role is the new role, or nil when they are no longer a member.
	Role *rendobar.MemberRole `json:"role"`
	// Reason says why Role is nil, or "".
	Reason    LeaveReason         `json:"reason"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

MemberUpdated is a member's role changing, or a member leaving.

func (MemberUpdated) EventID

func (c MemberUpdated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*MemberUpdated) Type

func (*MemberUpdated) Type() string

type Metric

type Metric struct {
	Number *float64 // set for a number
	Text   string   // set for a text
}

Metric is one value a job reports with its progress: a number or a text.

func (*Metric) UnmarshalJSON

func (m *Metric) UnmarshalJSON(b []byte) error

UnmarshalJSON reads a number or a string.

type Notification

type Notification struct {
	ID          string                        `json:"id"`
	Severity    rendobar.NotificationSeverity `json:"severity"`
	Title       string                        `json:"title"`
	Message     string                        `json:"message"`
	Href        string                        `json:"href"` // a dashboard path it is about, or ""
	RequiresAck bool                          `json:"requiresAck"`
	// contains filtered or unexported fields
}

Notification is a notification for the workspace.

func (Notification) EventID

func (c Notification) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*Notification) Type

func (*Notification) Type() string

type Option

type Option func(*config)

Option configures a Client.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets the API key. Without it, the client reads RENDOBAR_API_KEY. The key needs the jobs:read scope.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL points the client at another API host, as rendobar.WithBaseURL does. The default is rendobar.DefaultBaseURL. http becomes ws and https wss.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets the HTTP client the WebSocket handshake goes through.

type OrgUpdated

type OrgUpdated struct {
	Name      string              `json:"name"`
	Slug      string              `json:"slug"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

OrgUpdated is the workspace renamed or given another slug.

func (OrgUpdated) EventID

func (c OrgUpdated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*OrgUpdated) Type

func (*OrgUpdated) Type() string

type Phase

type Phase string

Phase is where a job is, for a progress display. The API may add phases.

const (
	PhasePreparing  Phase = "preparing"
	PhaseProcessing Phase = "processing"
	PhaseFinalizing Phase = "finalizing"
)

The Phase values this SDK knows.

type ReplayDone

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

ReplayDone says the replayed events are over: what follows is live.

func (ReplayDone) EventID

func (c ReplayDone) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*ReplayDone) Type

func (*ReplayDone) Type() string

type Resync

type Resync struct {
	Reason ResyncReason `json:"reason"`
	// contains filtered or unexported fields
}

Resync says the stream lost events it cannot replay. Read the state you show again, such as Jobs.List.

func (Resync) EventID

func (c Resync) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*Resync) Type

func (*Resync) Type() string

type ResyncReason

type ResyncReason string

ResyncReason says why the stream asks for a resync.

const (
	ResyncBufferOverflow ResyncReason = "buffer_overflow"
	ResyncServerRestart  ResyncReason = "server_restart"
)

The ResyncReason values this SDK knows. The API may add values.

type StorageConnected

type StorageConnected struct {
	ID        string              `json:"id"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

StorageConnected is a storage connection that finished connecting, such as an AWS stack reporting in.

func (StorageConnected) EventID

func (c StorageConnected) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*StorageConnected) Type

func (*StorageConnected) Type() string

type StorageProblem

type StorageProblem struct {
	ID        string              `json:"id"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

StorageProblem says a storage connection failed. Storage.Get says why.

func (StorageProblem) EventID

func (c StorageProblem) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*StorageProblem) Type

func (*StorageProblem) Type() string

type StorageRemoved

type StorageRemoved struct {
	ID        string              `json:"id"`
	Timestamp rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

StorageRemoved is a storage connection that went away, such as its AWS stack being deleted.

func (StorageRemoved) EventID

func (c StorageRemoved) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*StorageRemoved) Type

func (*StorageRemoved) Type() string

type SubscriptionUpdated

type SubscriptionUpdated struct {
	PlanID            string              `json:"planId"`
	Status            string              `json:"status"`
	CancelAtPeriodEnd *bool               `json:"cancelAtPeriodEnd"`
	Timestamp         rendobar.UnixMillis `json:"timestamp"`
	// contains filtered or unexported fields
}

SubscriptionUpdated is the workspace's plan subscription changing.

func (SubscriptionUpdated) EventID

func (c SubscriptionUpdated) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*SubscriptionUpdated) Type

func (*SubscriptionUpdated) Type() string

type Unknown

type Unknown struct {
	Name string
	Raw  json.RawMessage
	// contains filtered or unexported fields
}

Unknown is a message this SDK cannot read: a type newer than it, or a known type whose fields changed shape. Raw is the message as sent.

func (Unknown) EventID

func (c Unknown) EventID() int64

EventID returns the event's replay cursor, or 0.

func (*Unknown) Type

func (e *Unknown) Type() string

Jump to

Keyboard shortcuts

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