From 57b104e675582c2906946e43e66d28bcb1bc324e Mon Sep 17 00:00:00 2001 From: Alex Mazzeo Date: Mon, 27 Apr 2026 14:47:05 -0700 Subject: [PATCH] Nexus samples: use business IDs for workflow IDs (#297) * Nexus samples: use business IDs for workflow IDs. Stop using the Nexus request ID (nexus_cancel) or bare uuid4 (hello_nexus, nexus_multiple_args) as the backing workflow ID. Build a meaningful business ID from the operation input and append a uuid4 suffix for uniqueness. Co-Authored-By: Claude Opus 4.7 (1M context) * remove UUID from the nexus sample workflow ids to better communicate intent --------- Co-authored-by: Claude Opus 4.7 (1M context) --- hello_nexus/handler/service_handler.py | 4 +--- nexus_cancel/handler/service_handler.py | 7 ++++--- nexus_multiple_args/handler/service_handler.py | 4 +--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/hello_nexus/handler/service_handler.py b/hello_nexus/handler/service_handler.py index 1295abd1..812a5c5d 100644 --- a/hello_nexus/handler/service_handler.py +++ b/hello_nexus/handler/service_handler.py @@ -4,8 +4,6 @@ from __future__ import annotations -import uuid - import nexusrpc from temporalio import nexus @@ -33,7 +31,7 @@ async def my_workflow_run_operation( return await ctx.start_workflow( WorkflowStartedByNexusOperation.run, input, - id=str(uuid.uuid4()), + id=f"hello-nexus-workflow-{input.name}", ) # This is a Nexus operation that responds synchronously to all requests. That means diff --git a/nexus_cancel/handler/service_handler.py b/nexus_cancel/handler/service_handler.py index 92868510..5d75e8a6 100644 --- a/nexus_cancel/handler/service_handler.py +++ b/nexus_cancel/handler/service_handler.py @@ -1,8 +1,9 @@ """ Nexus service handler for the cancellation sample. -The hello operation is backed by a workflow, using the Nexus request ID as the -workflow ID for idempotency across retries. +The hello operation is backed by a workflow whose ID is derived from the +operation input (name + language), giving each fan-out branch a distinct, +meaningful business ID. """ from __future__ import annotations @@ -23,5 +24,5 @@ async def hello( return await ctx.start_workflow( HelloHandlerWorkflow.run, input, - id=ctx.request_id, + id=f"hello-handler-{input.name}-{input.language.name}", ) diff --git a/nexus_multiple_args/handler/service_handler.py b/nexus_multiple_args/handler/service_handler.py index c2ddfb92..8c00ee31 100644 --- a/nexus_multiple_args/handler/service_handler.py +++ b/nexus_multiple_args/handler/service_handler.py @@ -1,7 +1,5 @@ from __future__ import annotations -import uuid - import nexusrpc from temporalio import nexus @@ -32,7 +30,7 @@ async def hello( input.name, # First argument: name input.language, # Second argument: language ], - id=str(uuid.uuid4()), + id=f"hello-multi-args-{input.name}-{input.language}", )