Skip to content

Commit 57b104e

Browse files
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) <noreply@anthropic.com> * remove UUID from the nexus sample workflow ids to better communicate intent --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ba9e9a1 commit 57b104e

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

hello_nexus/handler/service_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from __future__ import annotations
66

7-
import uuid
8-
97
import nexusrpc
108
from temporalio import nexus
119

@@ -33,7 +31,7 @@ async def my_workflow_run_operation(
3331
return await ctx.start_workflow(
3432
WorkflowStartedByNexusOperation.run,
3533
input,
36-
id=str(uuid.uuid4()),
34+
id=f"hello-nexus-workflow-{input.name}",
3735
)
3836

3937
# This is a Nexus operation that responds synchronously to all requests. That means

nexus_cancel/handler/service_handler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""
22
Nexus service handler for the cancellation sample.
33
4-
The hello operation is backed by a workflow, using the Nexus request ID as the
5-
workflow ID for idempotency across retries.
4+
The hello operation is backed by a workflow whose ID is derived from the
5+
operation input (name + language), giving each fan-out branch a distinct,
6+
meaningful business ID.
67
"""
78

89
from __future__ import annotations
@@ -23,5 +24,5 @@ async def hello(
2324
return await ctx.start_workflow(
2425
HelloHandlerWorkflow.run,
2526
input,
26-
id=ctx.request_id,
27+
id=f"hello-handler-{input.name}-{input.language.name}",
2728
)

nexus_multiple_args/handler/service_handler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from __future__ import annotations
22

3-
import uuid
4-
53
import nexusrpc
64
from temporalio import nexus
75

@@ -32,7 +30,7 @@ async def hello(
3230
input.name, # First argument: name
3331
input.language, # Second argument: language
3432
],
35-
id=str(uuid.uuid4()),
33+
id=f"hello-multi-args-{input.name}-{input.language}",
3634
)
3735

3836

0 commit comments

Comments
 (0)