conductor

package module
v0.0.0-...-c11405c Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 26 Imported by: ? 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 conductor connects a worker process to RunnerQ Cloud.

The agent dials out over a WebSocket and answers the Cloud's requests from the engine's own storage backend; the Cloud never connects in and never holds database credentials. It is off the execution path: activities keep running if the Cloud or the agent fails, and it reconnects with backoff.

engine, _ := runnerq.Builder().Backend(backend).Build()
agent, err := conductor.Start(ctx, engine, conductor.Config{
	URL:    "wss://cloud.runnerq.dev",
	APIKey: os.Getenv("RUNNERQ_CONDUCTOR_KEY"),
})
if err != nil { ... }
defer agent.Close(context.Background())
engine.Start(ctx)

Services that hold a backend themselves (RunnerQ Cloud's data plane) answer the same requests with a Handler, without a worker or connection.

The wire protocol is runnerq-spec's conductor protocol (protocol/conductor in github.com/runnerq/runnerq-spec).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

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

Agent is a running connection to RunnerQ Cloud.

func Start

func Start(ctx context.Context, engine *runnerq.WorkerEngine, cfg Config) (*Agent, error)

Start validates cfg and connects in the background, so an unreachable Cloud never delays the worker. The agent stops when ctx ends or on Close.

func (*Agent) Close

func (a *Agent) Close(ctx context.Context) error

Close says goodbye (so the Cloud records a deploy, not a crash), closes the connection and waits for the agent to stop or ctx to end. Call it before stopping the engine.

func (*Agent) Connected

func (a *Agent) Connected() bool

Connected reports whether the agent currently has a Cloud session.

func (*Agent) SessionID

func (a *Agent) SessionID() string

SessionID is the current Cloud session id, or "" while disconnected.

type Config

type Config struct {
	// URL is the Cloud gateway, e.g. "wss://cloud.runnerq.dev". /v1/agent is
	// appended when missing; http(s) maps to ws(s).
	URL string
	// APIKey authenticates the app. It is sent only in the Authorization
	// header, never in the URL.
	APIKey string
	// AllowControl lets the Cloud run commands (cancel, retry, run now,
	// reschedule, set priority, delete, signal). Off by default: read-only.
	AllowControl bool
	// MetadataOnly withholds payloads, results, errors and event details
	// whatever mode the Cloud asks for; the Cloud cannot relax it.
	MetadataOnly bool
	// Labels are executor tags (region, deploy version) the Cloud filters and
	// groups by, merged over WorkerConfig.Labels. Prefer WorkerConfig.Labels,
	// which every way of reporting to the Cloud carries.
	Labels map[string]string
	// MaxConcurrentRequests bounds requests served at once (default 16);
	// excess requests get "resource_exhausted" rather than queueing.
	MaxConcurrentRequests int
	// RequestTimeout bounds one request (default 30s).
	RequestTimeout time.Duration
	// MinReconnectDelay and MaxReconnectDelay bound the reconnect backoff
	// (defaults 1s and 30s). Each wait is jittered by ±50%.
	MinReconnectDelay time.Duration
	MaxReconnectDelay time.Duration
	Logger            *slog.Logger
}

Config configures the agent.

type Error

type Error struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Details map[string]any `json:"details,omitempty"`
}

Error is a failed request as sent on the wire.

func (*Error) Error

func (e *Error) Error() string

type Handler

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

Handler serves the Cloud protocol's queries and commands from a storage backend, as an agent does, but without a worker engine or a connection.

Reads cover whatever the backend's queries cover (for Postgres, every queue in its schema); commands act on the backend's own queue. Handler checks no caller identity and applies no deadline or size limit: the caller authorizes requests, scopes the backend to what they may see, and sets deadlines and bounds answer sizes.

func NewHandler

func NewHandler(backend storage.Storage, cfg HandlerConfig) *Handler

NewHandler returns a Handler for backend. It serves queries when backend implements storage.QueryStorage, and commands when it implements storage.CommandStorage, reports its queue and cfg allows them.

func (*Handler) Capabilities

func (h *Handler) Capabilities() json.RawMessage

Capabilities describes what the handler serves as a JSON object keyed by message type, as in an agent's hello.

func (*Handler) Serve

func (h *Handler) Serve(ctx context.Context, msgType string, data json.RawMessage) (res json.RawMessage, werr *Error)

Serve answers one request (msgType and data from its envelope) with the response data or the error to send instead. Handler panics become errors.

type HandlerConfig

type HandlerConfig struct {
	// AllowControl serves commands (cancel, retry, run now, reschedule, set
	// priority, delete, signal) when the backend supports them and has a
	// QueueName() string method; targets naming another queue fail.
	AllowControl bool
}

HandlerConfig configures a Handler.

Directories

Path Synopsis
internal
wire
Package wire holds the Conductor protocol's types, generated from the runnerq-spec submodule's protocol/conductor/conductor.schema.json.
Package wire holds the Conductor protocol's types, generated from the runnerq-spec submodule's protocol/conductor/conductor.schema.json.

Jump to

Keyboard shortcuts

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