ops

package
v0.6.36 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 52 Imported by: 0

Documentation

Overview

Package ops is the console's operations on the stack behind the services (§8, §9, §11): events and their streams, consumers and dead letters in NATS JetStream; workflows, runs and schedules in Temporal; calling a hook or an activity by hand. It serves backplane.console.v1.EventService, WorkflowService, ScheduleService and CallService on the console's /ws.

backplane is a service on its own SDK, and ops uses the SDK's clients: event.JetStream for NATS (BACKPLANE_NATS_URL), workflows.Client for Temporal (BACKPLANE_TEMPORAL_ADDR). Without one the calls it backs fail with UNAVAILABLE. Hook and activity calls run as short workflows on backplane's own task queue (RegisterWorkflows, through workflows.Register): the run is in Temporal like any other, with memo source = console:<session>.

What the console declares — events, subscriptions, workflows, schedules, hooks, activities — comes from the latest manifest of each service (registry). Mutating calls are logged with their author (the console session): "console action".

Index

Constants

View Source
const (
	// CallHookWorkflow raises a hook: the Nexus operation of the hook's
	// service, input HookCall, output HookResult.
	CallHookWorkflow = "backplane.console.CallHook.v1"
	// RunActivityWorkflow executes an activity by name on its service's
	// queue: input ActivityRun, output ActivityResult.
	RunActivityWorkflow = "backplane.console.RunActivity.v1"
)

Workflows of the calls, on backplane's task queue. The version is in the name, as with backplane.CallHook.v1: a change that is not replay-compatible is a new name.

View Source
const SessionMetadata = "bp-console-session"

SessionMetadata is the gRPC metadata the console puts the operator's session in (§11.1).

Variables

View Source
var (
	// ErrNotSynced: the registry has no snapshot yet.
	ErrNotSynced = errors.New("ops: registry not synced yet")
	// ErrNoService: no service of that name.
	ErrNoService = errors.New("ops: no such service")
	// ErrNotDeclared: the latest manifest does not declare it.
	ErrNotDeclared = errors.New("ops: not declared")
	// ErrInput: the request is malformed.
	ErrInput = errors.New("ops: invalid request")
	// ErrPrecondition: the stack is not in a state the call needs.
	ErrPrecondition = errors.New("ops: failed precondition")
	// ErrExists: what the call would create exists (a running workflow id).
	ErrExists = errors.New("ops: already exists")
	// ErrUnavailable: NATS or Temporal is not configured or connected.
	ErrUnavailable = errors.New("ops: unavailable")
)

Errors.

View Source
var ErrNotSettled = errors.New("schedule change not applied yet")

ErrNotSettled: the schedule did not reach the requested state in time.

Functions

func HookWorkflowID

func HookWorkflowID(service, name, key string) string

HookWorkflowID is the run of a console hook call: with a key the same id as the service's own call with hook.Key(key), else a fresh one.

func RegisterWorkflows

func RegisterWorkflows(r worker.Registry)

RegisterWorkflows adds the call workflows to backplane's worker (give it to workflows.Register).

func RunsQuery

func RunsQuery(req *consolev1.ListRunsRequest, console string) (string, error)

RunsQuery is the visibility query of ListRuns, without ordering; console is backplane's queue, where the console's hook calls run.

Types

type ActivityRun

type ActivityRun struct {
	Service      string        `json:"service"`
	Name         string        `json:"name"`
	Workflow     bool          `json:"workflow"` // kind WORKFLOW: a child workflow
	Payload      []byte        `json:"payload"`
	Step         string        `json:"step"`
	StartToClose time.Duration `json:"start_to_close"`
	Heartbeat    time.Duration `json:"heartbeat"`
	MaxAttempts  int32         `json:"max_attempts"`
}

ActivityRun is the input of RunActivityWorkflow.

type CallAPI

type CallAPI struct {
	consolev1.UnimplementedCallServiceServer
	// contains filtered or unexported fields
}

CallAPI is backplane.console.v1.CallService.

func (CallAPI) CallHook

CallHook implements CallService: through the direct runtime when the hook's binding runs there (or it has none), else as a Temporal run.

func (CallAPI) RunActivity

RunActivity implements CallService: an activity is called over the direct transport (the service's platform port), a workflow-kind one runs as a Temporal child workflow.

type Direct added in v0.5.0

type Direct interface {
	// Runtime of the hook's active binding (direct for an unbound hook).
	Runtime(ctx context.Context, hook string) (consolev1.Runtime, error)
	// RaiseHook answers a hook call; the run id names a direct run.
	RaiseHook(ctx context.Context, call *backplanev1.HookCall) (*backplanev1.HookResult, string, error)
	// CallActivity calls one activity once, bounded by timeout.
	CallActivity(
		ctx context.Context, call *backplanev1.ActivityCall, timeout time.Duration,
	) (*backplanev1.ActivityResult, error)
}

Direct is the direct runtime: hook calls answered by bindings that run in backplane's process and activities called over the services' platform ports, no Temporal needed.

type EventAPI

type EventAPI struct {
	consolev1.UnimplementedEventServiceServer
	// contains filtered or unexported fields
}

EventAPI is backplane.console.v1.EventService.

func (EventAPI) GetStream

GetStream implements EventService.

func (EventAPI) ListDeadLetters

ListDeadLetters implements EventService.

func (EventAPI) ListEvents

ListEvents implements EventService.

func (EventAPI) PeekMessages

PeekMessages implements EventService.

func (EventAPI) PublishTestEvent

PublishTestEvent implements EventService. The event is the service's: ce-source is the service and ce-type its full name, as its emitter would publish it, so subscribers read it as any other; ce-instance is "backplane", ce-bptest "true" and ce-bpauthor the console session mark it as the console's.

func (EventAPI) PurgeDeadLetters

PurgeDeadLetters implements EventService.

func (EventAPI) RedriveDeadLetters

RedriveDeadLetters implements EventService. Each dead letter is published back to its reactor alone — to the reactor's redrive subject bp.<source>._redrive.<subscriber>.<consumer> in the source stream, which the reactor's consumer filters on next to its event (§8) — and then removed from the dead-letter stream. The reactor handles it as a new delivery (attempt 1, its full MaxDeliver again; ce-id unchanged, so an idempotent handler recognizes it); failing again, it becomes a new dead letter. Nats-Msg-Id redrive:<durable>:<seq> keeps a retried redrive of the same dead letter single within the dedup window.

type JetStreamFunc

type JetStreamFunc func() (jetstream.JetStream, error)

JetStreamFunc gives the NATS client; TemporalFunc the Temporal one.

type Ops

type Ops struct {
	deps.Component
	// contains filtered or unexported fields
}

Ops is the component. Every call reads the registry snapshot and asks NATS or Temporal; the one thing it remembers is whether Temporal's visibility refused ORDER BY.

func Detached

func Detached(src registry.Source, opts ...Option) *Ops

Detached is Ops without a node of the tree — it logs nowhere — for tests and tools: give it WithJetStream and WithTemporal, else the calls they back fail with UNAVAILABLE.

func New

func New(parent deps.Scope, src registry.Source, opts ...Option) *Ops

New creates the component under parent, reading declarations from src.

func (*Ops) Calls

func (o *Ops) Calls() CallAPI

Calls is o as CallService.

func (*Ops) Events

func (o *Ops) Events() EventAPI

Events is o as EventService.

func (*Ops) Register

func (o *Ops) Register(r grpc.ServiceRegistrar)

Register registers the console services on r.

func (*Ops) RunQueue

func (o *Ops) RunQueue(ctx context.Context, workflowID, runID string) (string, error)

RunQueue is the task queue of a run: where the audit finds the service a run command is addressed to when its id does not say.

func (*Ops) Schedules

func (o *Ops) Schedules() ScheduleAPI

Schedules is o as ScheduleService.

func (*Ops) SetDirect added in v0.5.0

func (o *Ops) SetDirect(d Direct)

SetDirect installs the direct runtime after construction (it is built after the console's components).

func (*Ops) Workflows

func (o *Ops) Workflows() WorkflowAPI

Workflows is o as WorkflowService.

type Option

type Option func(*Ops)

Option configures New.

func Author

func Author(fn func(ctx context.Context) string) Option

Author names who made a call from its context; default: the console session in SessionMetadata as console:<id>, else "admin".

func Namespace

func Namespace(ns string) Option

Namespace is the Temporal namespace of the client (default "default"): the calls that go to Temporal's API directly name it.

func WithDirect added in v0.5.0

func WithDirect(d Direct) Option

WithDirect installs the direct runtime: console calls of direct bindings and of activities go through it instead of Temporal.

func WithJetStream

func WithJetStream(fn JetStreamFunc) Option

WithJetStream replaces the SDK's NATS client (tests).

func WithTemporal

func WithTemporal(fn TemporalFunc, queue string) Option

WithTemporal replaces the SDK's Temporal client and backplane's task queue the call workflows run on (tests).

type ScheduleAPI

type ScheduleAPI struct {
	consolev1.UnimplementedScheduleServiceServer
	// contains filtered or unexported fields
}

ScheduleAPI is backplane.console.v1.ScheduleService.

func (ScheduleAPI) CreateSchedule

CreateSchedule uses a declared workflow and the platform's queue convention.

func (ScheduleAPI) DeleteSchedule

DeleteSchedule does not cancel running workflow executions.

func (ScheduleAPI) GetSchedule

GetSchedule reads from Temporal without requiring a currently running service.

func (ScheduleAPI) ListSchedules

ListSchedules implements ScheduleService.

func (ScheduleAPI) PauseSchedule

PauseSchedule implements ScheduleService.

func (ScheduleAPI) TriggerSchedule

TriggerSchedule implements ScheduleService.

func (ScheduleAPI) UnpauseSchedule

UnpauseSchedule implements ScheduleService.

func (ScheduleAPI) UpdateSchedule

UpdateSchedule preserves state and advanced action settings. Temporal checks the conflict token atomically, across all platform replicas and external tools.

type TemporalFunc

type TemporalFunc func() (client.Client, error)

JetStreamFunc gives the NATS client; TemporalFunc the Temporal one.

type WorkflowAPI

type WorkflowAPI struct {
	consolev1.UnimplementedWorkflowServiceServer
	// contains filtered or unexported fields
}

WorkflowAPI is backplane.console.v1.WorkflowService.

func (WorkflowAPI) CancelRun

CancelRun implements WorkflowService.

func (WorkflowAPI) GetRun

GetRun implements WorkflowService.

func (WorkflowAPI) ListRuns

ListRuns implements WorkflowService.

func (WorkflowAPI) ListWorkflows

ListWorkflows implements WorkflowService. Declarations come from the manifests; the pollers of each task queue from Temporal when it answers.

func (WorkflowAPI) SignalRun

SignalRun implements WorkflowService.

func (WorkflowAPI) StartWorkflow

StartWorkflow implements WorkflowService.

func (WorkflowAPI) TerminateRun

TerminateRun implements WorkflowService.

Jump to

Keyboard shortcuts

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