workflows

package
v0.6.41 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 13 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 ActivityRef added in v0.6.32

type ActivityRef[Req, Res any] struct {
	// contains filtered or unexported fields
}

ActivityRef is an activity of HandleActivity, for the service's own workflows to run.

func HandleActivity added in v0.6.32

func HandleActivity[Req, Res any](
	scope deps.Scope, name string, fn func(ctx context.Context, in Req) (Res, error),
) ActivityRef[Req, Res]

HandleActivity registers fn as an activity only the service's own workflows run (a saga's steps): on the service's worker, absent from the manifest, so no binding or rule can reach it. Otherwise it is activity.Handle's: payloads encoded as everywhere, fn's ctx carries activity.InfoOf and takes activity.Heartbeat, activity.NonRetryable stops the retries and activity.RetryAfter sets the next delay, a panic is a retried failure. name is CamelCase and shares the queue's activity names with activity.Handle: one taken panics.

charge := workflows.HandleActivity(root, "ChargeCard", billing.Charge)
// in a workflow, with workflow.WithActivityOptions on ctx:
receipt, err := charge.Execute(ctx, card)

func (ActivityRef[Req, Res]) Execute added in v0.6.32

func (r ActivityRef[Req, Res]) Execute(ctx workflow.Context, in Req) (Res, error)

Execute runs the activity from workflow code under ctx's activity options (workflow.WithActivityOptions: its timeouts and retry policy). The error keeps the Temporal error in its chain; a timeout matches context.DeadlineExceeded.

func (ActivityRef[Req, Res]) Name added in v0.6.32

func (r ActivityRef[Req, Res]) Name() string

Name is the activity's Temporal name.

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