Help us shape the future of Go! Take the 2026 Go Developer Survey

execution

package
v1.10.0-alpha.15 Latest Latest
Warning

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

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

Documentation

Overview

Package execution defines typed activity contracts for workflow adapters. It does not own persistence, workflow scheduling, or application policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Activity

type Activity[I, O any] struct {
	// Name must be stable across worker restarts and workflow replay.
	Name string
}

Activity binds a stable activity name to its input and output types. Reusing the same value for registration and invocation keeps both ends typed.

func (Activity[I, O]) Execute

func (a Activity[I, O]) Execute(ctx context.Context, executor ActivityExecutor, input I, opts ActivityOptions) (O, error)

Execute schedules the activity and waits for its typed result.

func (Activity[I, O]) ExecuteAsync

func (a Activity[I, O]) ExecuteAsync(ctx context.Context, executor ActivityExecutor, input I, opts ActivityOptions) (Future[O], error)

ExecuteAsync schedules the activity without waiting for completion.

func (Activity[I, O]) Register

func (a Activity[I, O]) Register(ctx context.Context, registrar ActivityRegistrar, opts ActivityOptions, fn func(context.Context, I) (O, error)) error

Register installs the typed handler and its default scheduling options.

type ActivityCall

type ActivityCall struct {
	// Name identifies a registered activity.
	Name string
	// Input is passed to the backend codec without a wrapper envelope.
	Input any
	// Options overrides registration defaults according to backend rules.
	Options ActivityOptions
}

ActivityCall carries a typed input unchanged to the backend's serializer.

type ActivityDefinition

type ActivityDefinition struct {
	// Name identifies the activity within its backend registry.
	Name string
	// Options supplies portable registration defaults.
	Options ActivityOptions
	// Handler must be func(context.Context, I) (O, error) or func(context.Context, I) error.
	// Use Activity[I, O].Register for compile-time checking of input and output.
	Handler any
}

ActivityDefinition describes an activity independently of agent payload types.

type ActivityExecutor

type ActivityExecutor interface {
	// ExecuteActivity schedules and waits for a result, decoded into a pointer.
	ExecuteActivity(context.Context, ActivityCall, any) error
	// ExecuteActivityAsync schedules a command in this executor's workflow scope.
	ExecuteActivityAsync(context.Context, ActivityCall) (ActivityFuture, error)
}

ActivityExecutor schedules named activities in a workflow scope. Results must be decoded into the supplied pointer using the backend's codec.

type ActivityFuture

type ActivityFuture interface {
	// Get waits using the captured workflow scope and decodes into a pointer.
	Get(context.Context, any) error
	// IsReady reports completion without blocking.
	IsReady() bool
}

ActivityFuture is the backend result boundary. Application code should use Activity[I, O], which exposes Future[O] instead of result pointers.

type ActivityOptions

type ActivityOptions struct {
	// Queue overrides the activity queue. Empty uses registration or backend defaults.
	Queue string
	// RetryPolicy controls retry behavior for this activity. If zero-valued, the
	// engine uses its default retry policy.
	RetryPolicy RetryPolicy
	// ScheduleToStartTimeout bounds how long the activity may wait in the task
	// queue before a worker starts the attempt. Zero means leave queue-wait
	// unspecified here and let the engine adapter apply its own defaults.
	ScheduleToStartTimeout time.Duration
	// StartToCloseTimeout bounds one activity attempt once a worker has started
	// executing it. Zero means use the engine default.
	StartToCloseTimeout time.Duration
	// HeartbeatTimeout bounds the maximum gap between heartbeats emitted by the
	// running activity. Zero leaves the backend default unchanged.
	HeartbeatTimeout time.Duration
}

ActivityOptions configures retry and timeouts for an activity.

type ActivityRegistrar

type ActivityRegistrar interface {
	// RegisterActivity validates and installs a concrete handler.
	RegisterActivity(context.Context, ActivityDefinition) error
}

ActivityRegistrar installs activities before workers begin polling.

type Future

type Future[T any] interface {
	// Get blocks until the activity completes and returns the typed result.
	// Once completed, repeated calls return the recorded result.
	Get(ctx context.Context) (T, error)

	// IsReady returns true if the activity has completed (success or failure) and Get()
	// will not block. This allows workflows to poll or implement custom waiting strategies.
	IsReady() bool
}

Future represents a pending activity result. It belongs to the workflow execution that scheduled it and must not be shared across workflows. Waiting and cancellation follow the selected backend's rules.

type RetryPolicy

type RetryPolicy struct {
	// MaxAttempts caps total attempts, including the first. Zero uses backend defaults.
	MaxAttempts int
	// InitialInterval is the delay before the first retry. Zero means use engine default.
	InitialInterval time.Duration
	// BackoffCoefficient multiplies the delay after each retry. Zero uses backend
	// defaults; the backend defines the valid range of explicit coefficients.
	BackoffCoefficient float64
}

RetryPolicy defines retry semantics shared by workflows and activities. Zero-valued fields mean the engine uses its defaults.

Directories

Path Synopsis
Package adapter implements the type-erased adapter boundary for typed activities.
Package adapter implements the type-erased adapter boundary for typed activities.
Package selvedge binds execution activities to native Selvedge apps and workflow scopes.
Package selvedge binds execution activities to native Selvedge apps and workflow scopes.

Jump to

Keyboard shortcuts

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