Python SDK - Update decorator syntax
In Python, define an Update handler using the @workflow.update decorator on an async method. Define a validator using @handler.validator decorator. The update handler receives parameters and returns a typed result. The validator receives the same parameters and raises an exception to reject the Update.
Python SDK - Update implementation example
```python
@workflow.update
async def assign_task(self, task_name: str) -> AssignmentResult:
assignment_id = str(uuid.uuid4())
self.tasks.append(task_name)
return AssignmentResult(
assignment_id=assignment_id,
task_name=task_name,
total_tasks=len(self.tasks),
)
@assign_task.validator
def validate_assign_task(self, task_name: str) -> None:
if len(self.tasks) >= MAX_TASKS:
raise ValueError("Task limit reached")
```
Go SDK - Update handler setup syntax
In Go, use workflow.SetUpdateHandlerWithOptions() to register an Update handler. Pass the context, Update name as a string, a handler function that returns (result, error), and workflow.UpdateHandlerOptions containing a Validator function. The validator receives the same parameters as the handler and returns an error to reject the Update.
Go SDK - Update implementation example
```go
err := workflow.SetUpdateHandlerWithOptions(
ctx,
"AssignTask",
func(ctx workflow.Context, taskName string) (AssignmentResult, error) {
assignmentID := uuid.New().String()
tasks = append(tasks, taskName)
return AssignmentResult{
AssignmentID: assignmentID,
TaskName: taskName,
TotalTasks: len(tasks),
}, nil
},
workflow.UpdateHandlerOptions{
Validator: func(taskName string) error {
if len(tasks) >= MaxTasks {
return fmt.Errorf("task limit reached")
}
return nil
},
},
)
```
Java SDK - Update decorator syntax
In Java, define an Update handler using @UpdateMethod annotation on an interface method. Define a validator using @UpdateValidatorMethod annotation specifying the updateName. The validator method receives the same parameters as the handler and throws an exception to reject the Update.
Java SDK - Update implementation example
```java
@UpdateValidatorMethod(updateName = "assignTask")
protected void validateAssignTask(String taskName) {
if (tasks.size() >= MAX_TASKS) {
throw new IllegalStateException("Task limit reached");
}
}
@Override
public AssignmentResult assignTask(String taskName) {
String assignmentId = UUID.randomUUID().toString();
tasks.add(taskName);
return new AssignmentResult(assignmentId, taskName, tasks.size());
}
```
TypeScript SDK - Update handler syntax
In TypeScript, use wf.defineUpdate() to define an Update with generic type parameters for return type and parameter types. Use wf.setHandler() to register the Update handler, passing the defined Update, a handler function, and options containing a validator function. The validator receives the same parameters and throws an error to reject the Update.
TypeScript SDK - Update implementation example
```typescript
export const assignTaskUpdate = wf.defineUpdate<AssignmentResult, [string]>('assignTask');
wf.setHandler(
assignTaskUpdate,
(taskName: string): AssignmentResult => {
const assignmentId = wf.uuid4();
tasks.push(taskName);
return { assignmentId, taskName, totalTasks: tasks.length };
},
{
validator: (taskName: string): void => {
if (tasks.length >= MAX_TASKS) {
throw new Error('Task limit reached');
}
},
}
);
```
Unregistered Activity invocation is Go SDK only
The unregistered_activity_invocation metric is emitted by the Go SDK only. It fires when a Workflow scheduled an Activity that the Worker polling that Task Queue has no registered implementation for.
Java SDK thread pool exhaustion failure
In the Java SDK, a RejectedExecutionException from a saturated Workflow thread pool causes WorkflowError failures. This occurs when setMaxWorkflowThreadCount on WorkerFactoryOptions is too low for the number of concurrent Executions, causing new Workflow Tasks to be rejected before they run.
Python SDK async event loop blocking causes high latency
In the Python SDK, verify that no async def Workflow code is blocking the event loop, as this causes high Workflow Task execution latency.
UpdateWithStartWorkflowExecution metric name in gRPC operations
`UpdateWithStartWorkflowExecution` shows up in SDK metrics under the gRPC operation name `ExecuteMultiOperation`.
Status code values are UPPER_SNAKE_CASE in SDK metrics
Status code values are `UPPER_SNAKE_CASE` in every SDK, matching the gRPC status code names. Client options can also turn the tag off, so check that it is present in your metrics endpoint before filtering on it.
Go SDK sticky workflow cache configuration
In the Go SDK, worker.SetStickyWorkflowCacheSize(int) sets the sticky workflow cache size, defaulting to 10,000. Passing 0 turns the cache off completely. This must be called before any Worker starts since the cache is shared across every Worker in the process.
Java SDK workflow cache size configuration
In the Java SDK, WorkerFactoryOptions.Builder.setWorkflowCacheSize(int) sets the workflow cache size, defaulting to 600. Passing 0 resets it to the default instead of disabling it, and a negative value is rejected. The cache cannot be disabled through this method.