function

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 9 Imported by: 0

README

Function Package

Temporal workflow activities for dispatching arbitrary Go functions. Uses a registry to map function names to implementations at runtime, executing them as Temporal activities that compose with the generic orchestration patterns in the workflow package.

Key Features

  • Function Registry — register named Go functions for Temporal dispatch
  • Type-safe payloads — implements workflow.TaskInput and workflow.TaskOutput
  • Composable — use with Pipeline, Parallel, Loop, and DAG workflows
  • Builder API — fluent construction of function workflow inputs
  • Pre-built patterns — common function orchestration patterns included

Documentation

Quick Example

// Register a handler
registry := function.NewRegistry()
registry.Register("greet", func(ctx context.Context, input function.FunctionInput) (*function.FunctionOutput, error) {
    name := input.Args["name"]
    return &function.FunctionOutput{
        Result: map[string]string{"greeting": fmt.Sprintf("Hello, %s!", name)},
    }, nil
})

// Execute via Temporal
input := function.FunctionExecutionInput{
    Name: "greet",
    Args: map[string]string{"name": "World"},
}

Documentation

Overview

Package function provides Temporal workflow activities for dispatching arbitrary Go functions.

It implements the workflow.TaskInput and workflow.TaskOutput interfaces with function-specific payload types and uses a Registry to map function names to their implementations at runtime. Registered functions are executed as Temporal activities and can be composed using the generic orchestration patterns in the workflow package (pipeline, parallel, loop, DAG).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterActivity

func RegisterActivity(w worker.Worker, activityFn interface{})

RegisterActivity registers a function execution activity with a worker. Create the activity with activity.NewExecuteFunctionActivity(registry). Calling this function multiple times on the same worker is a no-op for subsequent calls — the activity type is registered at most once per worker.

func RegisterAll

func RegisterAll(w worker.Worker, activityFn interface{})

RegisterAll registers all function workflows and the given activity with a worker. Create the activity with activity.NewExecuteFunctionActivity(registry). Calling this function multiple times on the same worker is a no-op for subsequent calls — idempotency is ensured via job.RegisterWorkflowOnce and job.RegisterActivityOnce.

func RegisterWorkflows

func RegisterWorkflows(w worker.Worker)

RegisterWorkflows registers all function workflows with a worker. Calling this function multiple times on the same worker is a no-op for subsequent calls — each workflow type is registered at most once per worker.

func SetActivityInstrumenter added in v1.7.0

func SetActivityInstrumenter(wrapper func(activityType) activityType)

SetActivityInstrumenter sets the function that wraps activities with instrumentation. This must only be called once during initialization; subsequent calls are ignored.

Types

type DAGWorkflowInput added in v1.16.0

type DAGWorkflowInput = payload.DAGWorkflowInput

Type aliases for extended (DAG) types re-exported from function/payload.

type DataMapping added in v1.16.0

type DataMapping = payload.DataMapping

Type aliases for extended (DAG) types re-exported from function/payload.

type FunctionDAGNode added in v1.16.0

type FunctionDAGNode = payload.FunctionDAGNode

Type aliases for extended (DAG) types re-exported from function/payload.

type FunctionDAGWorkflowOutput added in v1.16.0

type FunctionDAGWorkflowOutput = payload.FunctionDAGWorkflowOutput

Type aliases for extended (DAG) types re-exported from function/payload.

type FunctionExecutionInput added in v1.16.0

type FunctionExecutionInput = payload.FunctionExecutionInput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type FunctionExecutionOutput added in v1.16.0

type FunctionExecutionOutput = payload.FunctionExecutionOutput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type FunctionInput

type FunctionInput struct {
	Args    map[string]string `json:"args,omitempty"`
	Data    []byte            `json:"data,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	WorkDir string            `json:"work_dir,omitempty"`
}

FunctionInput is the input passed to registered handler functions.

type FunctionInputMapping added in v1.16.0

type FunctionInputMapping = payload.FunctionInputMapping

Type aliases for extended (DAG) types re-exported from function/payload.

type FunctionNodeResult added in v1.16.0

type FunctionNodeResult = payload.FunctionNodeResult

Type aliases for extended (DAG) types re-exported from function/payload.

type FunctionOutput

type FunctionOutput struct {
	Result map[string]string `json:"result,omitempty"`
	Data   []byte            `json:"data,omitempty"`
}

FunctionOutput is the output returned by registered handler functions.

type Handler

type Handler func(ctx context.Context, input FunctionInput) (*FunctionOutput, error)

Handler is the function signature for registered handlers.

type LoopInput added in v1.16.0

type LoopInput = payload.LoopInput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type LoopOutput added in v1.16.0

type LoopOutput = payload.LoopOutput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type OutputMapping added in v1.16.0

type OutputMapping = payload.OutputMapping

Type aliases for extended (DAG) types re-exported from function/payload.

type ParallelInput added in v1.16.0

type ParallelInput = payload.ParallelInput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type ParallelOutput added in v1.16.0

type ParallelOutput = payload.ParallelOutput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type ParameterizedLoopInput added in v1.16.0

type ParameterizedLoopInput = payload.ParameterizedLoopInput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type PipelineInput added in v1.16.0

type PipelineInput = payload.PipelineInput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type PipelineOutput added in v1.16.0

type PipelineOutput = payload.PipelineOutput

Type aliases re-exported from function/payload for convenience. External callers can use function.FunctionExecutionInput instead of function/payload.FunctionExecutionInput.

type Registry

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

Registry maps function names to handlers.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new empty function registry.

func (*Registry) Get

func (r *Registry) Get(name string) (Handler, error)

Get retrieves a handler by name.

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has returns true if a handler with the given name is registered.

func (*Registry) Register

func (r *Registry) Register(name string, handler Handler) error

Register adds a named handler to the registry. Returns an error if a handler with the same name is already registered.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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