new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Temporal · Develop · all subjects

dynamic-workflows

17 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Dynamic Workflow definition in 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. Register a Workflow as dynamic by using worker.RegisterDynamicWorkflow(). Only one Dynamic Workflow can be present on a Worker.

Dynamic Workflow function signature in Go SDK

The Workflow Definition must accept a single argument of type converter.EncodedValues. The function signature is func DynamicWorkflow(ctx workflow.Context, args converter.EncodedValues) (string, error).

Register Dynamic Workflow before invocation

A Dynamic Workflow must be registered with the Worker before it can be invoked.

Example: Dynamic Workflow with runtime dispatch in 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 } This example shows how to decode EncodedValues arguments, inspect the workflow type name at runtime via workflow.GetInfo(), and conditionally dispatch to different logic. It demonstrates executing a dynamic activity name and handling errors.

Decode arguments in Dynamic Workflow

Use args.Get() to decode the EncodedValues arguments into typed variables. This method takes pointers to the expected argument types and returns an error if decoding fails.

Access workflow type name in Dynamic Workflow

Use workflow.GetInfo(ctx) to access workflow metadata, then check info.WorkflowType.Name to determine which workflow type is being executed at runtime. This enables conditional logic based on the workflow type.

DynamicWorkflow handles unregistered Workflow Types

Use DynamicWorkflow when you need a default Workflow that can handle all Workflow Types that are not registered with a Worker. A single implementation can implement a Workflow Type which by definition is dynamically loaded from some external source. All standard WorkflowOptions and determinism rules apply to Dynamic Workflow implementations.

Dynamic workflows omit @WorkflowMethod annotation

When using dynamic Workflows, do not specify a @WorkflowMethod, and implement the DynamicWorkflow directly in the Workflow implementation code.

Example: DynamicWorkflow in Java

public class MyDynamicWorkflow implements DynamicWorkflow { @Override public Object execute(EncodedValues args) { } } This example shows the basic implementation of DynamicWorkflow with the execute method that takes EncodedValues.

Example: DynamicQueryHandler in Java

Workflow.registerListener( (DynamicQueryHandler) (queryName, encodedArgs) -> name = encodedArgs.get(0, String.class)); This example shows how to register a DynamicQueryHandler using Workflow.registerListener().

DynamicWorkflow in Java

Use DynamicWorkflow to implement Workflow Types dynamically. Register a Workflow implementation type that extends DynamicWorkflow to handle any Workflow Type not explicitly registered with the Worker. The dynamic Workflow interface is implemented with the execute method, which takes EncodedValues as inputs to the Workflow Execution.

DynamicQueryHandler in Java

Implement Query handlers dynamically using DynamicQueryHandler. Register the handler with Workflow.registerListener(Object). When registered, any Queries sent to the Workflow without a defined handler are delivered to the DynamicQueryHandler. You can only register one Workflow.registerListener(Object) per Workflow Execution. DynamicQueryHandler can be implemented in both regular and dynamic Workflow implementations.

DynamicUpdateHandler in Java

Implement Update handlers dynamically using DynamicUpdateHandler. Register the handler with Workflow.registerListener(Object). When registered, any Updates sent to the Workflow without a defined handler are delivered to the DynamicUpdateHandler. You can only register one Workflow.registerListener(Object) per Workflow Execution. DynamicUpdateHandler can be implemented in both regular and dynamic Workflow implementations.

Example: DynamicUpdateHandler in Java

Workflow.registerListener( (DynamicUpdateHandler) (updateName, encodedArgs) -> encodedArgs.get(0, String.class)); This example shows how to register a DynamicUpdateHandler using Workflow.registerListener().

Dynamic Workflow definition in Ruby 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 is made dynamic by invoking the `workflow_dynamic` class method at the top of the definition. Only one Dynamic Workflow can be present on a Worker. The Workflow must be registered with the Worker before it can be invoked.

workflow_raw_args usage with dynamic workflows in Ruby

The `workflow_raw_args` method can be used in conjunction with dynamic workflows. It does not convert arguments but instead passes them through as a splatted array of `Temporalio::Converters::RawValue` instances. This allows manual control over argument conversion within the workflow.

Ruby dynamic workflow example with raw args

Example of a dynamic workflow in Ruby SDK: ```ruby class MyDynamicWorkflow < Temporalio::Workflow::Definition workflow_dynamic workflow_raw_args def execute(*raw_args) raise Temporalio::Error::ApplicationError, 'One arg expected' unless raw_args.size == 1 name = Temporalio::Workflow.payload_converter.from_payload(raw_args.first.payload) Temporalio::Workflow.execute_activity( MyActivity, { greeting: 'Hello', name: }, start_to_close_timeout: 100 ) end end ``` This shows how to access the payload converter within a dynamic workflow to manually convert raw value arguments.

Give your agent this brain