workflows

package
v0.6.24 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package workflows gives a service its own Temporal workflows (design §9): the SDK owns the connection and the worker on the service's task queue (= its name); the author registers on it and uses the client. Between services go through hooks, never through another service's queue.

workflows.Register(root, func(r worker.Registry) {
    r.RegisterWorkflow(orders.Ship)
    r.RegisterActivity(orders.Charge)
})

c, err := workflows.Client(scope)
run, err := c.ExecuteWorkflow(ctx, client.StartWorkflowOptions{TaskQueue: workflows.Queue(scope)}, orders.Ship, in)

Declare registers one workflow and records it in the manifest with its input and output schemas, so the console can start it with a form:

workflows.Declare(root, "Ship", orders.Ship, workflows.Describe("ships an order"))

Schedules are managed by the platform administrative API, never by SDK startup.

The worker is tuned by configuration, not code: BACKPLANE_TEMPORAL_WORKER_* (config.Worker).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Activity

func Activity[Req, Res any](
	scope deps.Scope, name string, fn func(ctx workflow.Context, in Req) (Res, error), opts ...activity.Option,
)

Activity declares a workflow-backed activity: a binding step runs fn as a child workflow of type name on the service's queue, so the activity may itself wait, sleep, call hooks (workflows.CallHook) and run activities. name is CamelCase; errors map as for Handle (NonRetryable included).

func CallHook

func CallHook[Req, Res any](ctx workflow.Context, r hook.Ref[Req, Res], in Req, opts ...hook.CallOption) (Res, error)

CallHook raises the hook from workflow code: the Nexus operation directly, no extra workflow. The deadline is Timeout, else the declared DefaultTimeout, else the platform default — cut to what is left of the run's timeout; a call is never unbounded. The error is readable ("hook <service>.<Name>: no binding") and matches ErrNoBinding when there is no binding.

func Client

func Client(scope deps.Scope) (client.Client, error)

Client is the service's Temporal client. It fails with an error wrapping hook.ErrUnavailable while Temporal is not configured or not connected.

func Declare

func Declare[In, Out any](
	scope deps.Scope, name string, fn func(ctx workflow.Context, in In) (Out, error), opts ...DeclareOption,
)

Declare registers fn on the service's worker as workflow type name and records it in the manifest with the schemas of In and Out, so the console can start it with a form. name is CamelCase ([A-Z][A-Za-z0-9]*), anything else panics; declaring after Run panics. The input arrives through Temporal's default converter: JSON, protojson for proto messages. A workflow Declare registered is not registered again with Register.

workflows.Declare(root, "Ship", orders.Ship, workflows.Describe("ships an order"))

func Queue

func Queue(scope deps.Scope) string

Queue is the service's task queue.

func Register

func Register(scope deps.Scope, fn func(r worker.Registry))

Register adds fn's workflows and activities to the service's worker. Declare it before Run, like any declaration.

Types

type DeclareOption

type DeclareOption func(w *backplanev1.Workflow)

DeclareOption tunes Declare.

func Describe

func Describe(s string) DeclareOption

Describe is the workflow's description for the console.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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