From f997ffd95b3fce60b28f3a7289e41265ffbb98a1 Mon Sep 17 00:00:00 2001 From: Andrew Yuan Date: Thu, 17 Jul 2025 16:34:58 -0700 Subject: [PATCH 1/2] dynamic workflow/activities docs --- docs/develop/go/core-application.mdx | 64 ++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/develop/go/core-application.mdx b/docs/develop/go/core-application.mdx index 8457b558cf..ed72946fdd 100644 --- a/docs/develop/go/core-application.mdx +++ b/docs/develop/go/core-application.mdx @@ -56,6 +56,8 @@ In this section you can find the following: - [Start an Activity Execution](#activity-execution) - [Run a dev Worker](#develop-worker) - [Run a Temporal Cloud Worker](#run-a-temporal-cloud-worker) +- [Set a Dynamic Workflow](#set-a-dynamic-workflow) +- [Set a Dynamic Activity](#set-a-dynamic-activity) ## How to install the Temporal CLI and run a development server {#run-a-development-server} @@ -1593,3 +1595,65 @@ registerOptions := activity.RegisterOptions{ w.RegisterActivityWithOptions(a.YourActivityDefinition, registerOptions) // ... ``` + +## Set a Dynamic Workflow {#set-a-dynamic-workflow} + +**How to set a Dynamic Workflow using the Temporal Go SDK** + +A Dynamic Workflow in Temporal is a Workflow that is invoked dynamically at runtime if no other Workflow with the same name is registered. +A Workflow can be registered as dynamic by using `worker.RegisterDynamicWorkflow()`. +You must register the Workflow with the Worker before it can be invoked. +Only one Dynamic Workflow can be present on a Worker. + +The Workflow Definition must then accept a single argument of type `converter.EncodedValues`. +This code snippet is taken from the [Dynamic Workflow example from samples-go](https://github.com/temporalio/samples-go/tree/main/dynamic-workflows). +```go +func DynamicWorkflow(ctx workflow.Context, args converter.EncodedValues) (string, error) { + var result string + info := workflow.GetInfo(ctx) + + var arg1, arg2 string + err := args.Get(&arg1, &arg2) + if err != nil { + return "", fmt.Errorf("failed to decode arguments: %w", err) + } + + if info.WorkflowType.Name == "dynamic-activity" { + ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{StartToCloseTimeout: 10 * time.Second}) + err := workflow.ExecuteActivity(ctx, "random-activity-name", arg1, arg2).Get(ctx, &result) + if err != nil { + return "", err + } + } else { + result = fmt.Sprintf("%s - %s - %s", info.WorkflowType.Name, arg1, arg2) + } + + return result, nil +} +``` + +## Set a Dynamic Activity {#set-a-dynamic-activity} + +**How to set a Dynamic Activity using the Temporal Go SDK** + +A Dynamic Activity in Temporal is an Activity that is invoked dynamically at runtime if no other Activity with the same name is registered. +A Workflow can be registered as dynamic by using `worker.RegisterDynamicActivity()`. +You must register the Activity with the Worker before it can be invoked. +Only one Dynamic Activity can be present on a Worker. + +The Workflow Definition must then accept a single argument of type `converter.EncodedValues`. +This code snippet is taken from the [Dynamic Workflow example from samples-go](https://github.com/temporalio/samples-go/tree/main/dynamic-workflows). +```go +func DynamicActivity(ctx context.Context, args converter.EncodedValues) (string, error) { + var arg1, arg2 string + err := args.Get(&arg1, &arg2) + if err != nil { + return "", fmt.Errorf("failed to decode arguments: %w", err) + } + + info := activity.GetInfo(ctx) + result := fmt.Sprintf("%s - %s - %s", info.WorkflowType.Name, arg1, arg2) + + return result, nil +} +``` From 708b969954f751ab7625982fa902065eb585dbcb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 17 Jul 2025 23:35:48 +0000 Subject: [PATCH 2/2] CI: Automatic .md and .mdx formatting --- docs/develop/go/core-application.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/develop/go/core-application.mdx b/docs/develop/go/core-application.mdx index ed72946fdd..3cb2e730f7 100644 --- a/docs/develop/go/core-application.mdx +++ b/docs/develop/go/core-application.mdx @@ -1607,6 +1607,7 @@ Only one Dynamic Workflow can be present on a Worker. The Workflow Definition must then accept a single argument of type `converter.EncodedValues`. This code snippet is taken from the [Dynamic Workflow example from samples-go](https://github.com/temporalio/samples-go/tree/main/dynamic-workflows). + ```go func DynamicWorkflow(ctx workflow.Context, args converter.EncodedValues) (string, error) { var result string @@ -1643,6 +1644,7 @@ Only one Dynamic Activity can be present on a Worker. The Workflow Definition must then accept a single argument of type `converter.EncodedValues`. This code snippet is taken from the [Dynamic Workflow example from samples-go](https://github.com/temporalio/samples-go/tree/main/dynamic-workflows). + ```go func DynamicActivity(ctx context.Context, args converter.EncodedValues) (string, error) { var arg1, arg2 string