new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Temporal · Develop · all subjects

activities/dynamic

11 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 Activity method signature in .NET SDK

The Activity Definition for a Dynamic Activity must accept a single argument of type `Temporalio.Converters.IRawValue[]`. The `PayloadConverter` property on the `ActivityExecutionContext` is used to convert an `IRawValue` object to the desired type using extension methods in the `Temporalio.Converters` namespace.

Dynamic Activity example in .NET SDK

This example shows a Dynamic Activity that accepts `IRawValue[]` arguments and converts them to the desired type using the PayloadConverter: ```csharp public class MyActivities { [Activity(Dynamic = true)] public string DynamicActivity(IRawValue[] args) { var input = ActivityExecutionContext.Current.PayloadConverter.ToValue<MyActivityParams>(args.Single()); return $"{input.Greeting}, {input.Name}!"; } } ```

.NET Activities - Dynamic Activity supported

The .NET SDK supports dynamic Activities, which is documented as a distinct feature topic.

Dynamic Activity definition and registration

A Dynamic Activity in Temporal is an Activity that is invoked dynamically at runtime if no other Activity with the same name is registered. An Activity can be registered as dynamic by using worker.RegisterDynamicActivity(). Only one Dynamic Activity can be present on a Worker. The Activity must be registered with the Worker before it can be invoked.

Dynamic Activity argument type

The Activity Definition for a Dynamic Activity must accept a single argument of type converter.EncodedValues. This allows the activity to receive variable arguments that are decoded at runtime.

Dynamic Activity example with argument decoding

This example shows a Dynamic Activity that decodes multiple arguments from converter.EncodedValues, retrieves activity information using activity.GetInfo(), and returns a formatted string: 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 }

DynamicActivity for dynamic Activity handling

To handle Activity types that do not have an explicitly registered handler, you can directly implement a dynamic Activity. The DynamicActivity interface has an execute method that takes in EncodedValues that are inputs to the Activity Execution. The execute method for DynamicActivity can return type Object. Ensure that your Workflow or Client can handle an Object type return or is able to convert the Object type response.

DynamicActivity implementation - example

public static class DynamicActivityImpl implements DynamicActivity { @Override public Object execute(EncodedValues args) { String activityType = Activity.getExecutionContext().getInfo().getActivityType(); return activityType + ": " + args.get(0, String.class) + " " + args.get(1, String.class) + " from: " + args.get(2, String.class); } }

Dynamic Activity definition in Ruby 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. An Activity can be made dynamic by invoking the `activity_dynamic` class method at the top of the definition. Only one Dynamic Activity can be present on a Worker. You must register the Activity with the Worker before it can be invoked.

activity_raw_args in Ruby SDK dynamic activities

The `activity_raw_args` class method can be used in conjunction with dynamic activities. When used, 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 using the payload converter.

Ruby SDK dynamic activity with raw args example

This example shows a Dynamic Activity in Ruby that accepts raw arguments and manually converts them using the payload converter: ```ruby class MyDynamicActivity < Temporalio::Activity::Definition # Make this the dynamic activity and accept raw args activity_dynamic activity_raw_args def execute(*raw_args) raise Temporalio::Error::ApplicationError, 'One arg expected' unless raw_args.size == 1 # Use payload converter to convert it input = Temporalio::Activity::Context.current.payload_converter.from_payload(raw_args.first.payload) "#{input['greeting']}, #{input['name']}!" end end ``` This example demonstrates using `activity_dynamic` and `activity_raw_args` class methods, handling raw arguments as a splatted array, validating argument count, and manually converting payloads using the context's payload converter.

Give your agent this brain