diff --git a/src/NexusCancellation/Handler/HelloService.cs b/src/NexusCancellation/Handler/HelloService.cs index 69fbd1f..2aa9219 100644 --- a/src/NexusCancellation/Handler/HelloService.cs +++ b/src/NexusCancellation/Handler/HelloService.cs @@ -14,8 +14,11 @@ public class HelloService context.StartWorkflowAsync( (HelloHandlerWorkflow wf) => wf.RunAsync(input), // Workflow IDs should typically be business meaningful IDs and are used to - // dedupe workflow starts. For this example, we're using the request ID - // allocated by Temporal when the caller workflow schedules the operation, - // this ID is guaranteed to be stable across retries of this operation. - new() { Id = context.HandlerContext.RequestId })); -} \ No newline at end of file + // dedupe workflow starts. For this example, use a business ID derived from + // the greeting input so repeated operations for the same name and language + // resolve to the same workflow. + new() { Id = GetHelloWorkflowId(input) })); + + private static string GetHelloWorkflowId(IHelloService.HelloInput input) => + $"hello-{input.Language}-{input.Name.Trim().Replace(' ', '-')}"; +} diff --git a/src/NexusContextPropagation/Handler/HelloService.cs b/src/NexusContextPropagation/Handler/HelloService.cs index 413aa24..d4e9526 100644 --- a/src/NexusContextPropagation/Handler/HelloService.cs +++ b/src/NexusContextPropagation/Handler/HelloService.cs @@ -19,9 +19,12 @@ public class HelloService return context.StartWorkflowAsync( (HelloHandlerWorkflow wf) => wf.RunAsync(input), // Workflow IDs should typically be business meaningful IDs and are used to - // dedupe workflow starts. For this example, we're using the request ID - // allocated by Temporal when the caller workflow schedules the operation, - // this ID is guaranteed to be stable across retries of this operation. - new() { Id = context.HandlerContext.RequestId }); + // dedupe workflow starts. For this example, use a business ID derived from + // the greeting input so repeated operations for the same name and language + // resolve to the same workflow. + new() { Id = GetHelloWorkflowId(input) }); }); -} \ No newline at end of file + + private static string GetHelloWorkflowId(IHelloService.HelloInput input) => + $"hello-{input.Language}-{input.Name.Trim().Replace(' ', '-')}"; +} diff --git a/src/NexusMultiArg/Handler/HelloService.cs b/src/NexusMultiArg/Handler/HelloService.cs index 42c8414..1d98a45 100644 --- a/src/NexusMultiArg/Handler/HelloService.cs +++ b/src/NexusMultiArg/Handler/HelloService.cs @@ -15,8 +15,11 @@ public class HelloService context.StartWorkflowAsync( (HelloHandlerWorkflow wf) => wf.RunAsync(input.Language, input.Name), // Workflow IDs should typically be business meaningful IDs and are used to - // dedupe workflow starts. For this example, we're using the request ID - // allocated by Temporal when the caller workflow schedules the operation, - // this ID is guaranteed to be stable across retries of this operation. - new() { Id = context.HandlerContext.RequestId })); -} \ No newline at end of file + // dedupe workflow starts. For this example, use a business ID derived from + // the greeting input so repeated operations for the same name and language + // resolve to the same workflow. + new() { Id = GetHelloWorkflowId(input) })); + + private static string GetHelloWorkflowId(IHelloService.HelloInput input) => + $"hello-{input.Language}-{input.Name.Trim().Replace(' ', '-')}"; +} diff --git a/src/NexusSimple/Handler/HelloService.cs b/src/NexusSimple/Handler/HelloService.cs index bc58cf8..c518b5a 100644 --- a/src/NexusSimple/Handler/HelloService.cs +++ b/src/NexusSimple/Handler/HelloService.cs @@ -20,8 +20,11 @@ public class HelloService context.StartWorkflowAsync( (HelloHandlerWorkflow wf) => wf.RunAsync(input), // Workflow IDs should typically be business meaningful IDs and are used to - // dedupe workflow starts. For this example, we're using the request ID - // allocated by Temporal when the caller workflow schedules the operation, - // this ID is guaranteed to be stable across retries of this operation. - new() { Id = context.HandlerContext.RequestId })); -} \ No newline at end of file + // dedupe workflow starts. For this example, use a business ID derived from + // the greeting input so repeated operations for the same name and language + // resolve to the same workflow. + new() { Id = GetHelloWorkflowId(input) })); + + private static string GetHelloWorkflowId(IHelloService.HelloInput input) => + $"hello-{input.Language}-{input.Name.Trim().Replace(' ', '-')}"; +}