diff --git a/src/NexusCancellation/Handler/HelloService.cs b/src/NexusCancellation/Handler/HelloService.cs index 69fbd1f..ae81188 100644 --- a/src/NexusCancellation/Handler/HelloService.cs +++ b/src/NexusCancellation/Handler/HelloService.cs @@ -14,8 +14,12 @@ 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) })); + + // Create a business meaningful ID derived from the operation input. + private static string GetHelloWorkflowId(IHelloService.HelloInput input) => + $"hello-{input.Language}-{input.Name}"; +} diff --git a/src/NexusContextPropagation/Handler/HelloService.cs b/src/NexusContextPropagation/Handler/HelloService.cs index 413aa24..1ad9ca3 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}"; +} diff --git a/src/NexusMultiArg/Handler/HelloService.cs b/src/NexusMultiArg/Handler/HelloService.cs index 42c8414..aff04f8 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}"; +} diff --git a/src/NexusSimple/Handler/HelloService.cs b/src/NexusSimple/Handler/HelloService.cs index bc58cf8..f597ed3 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}"; +}