Skip to content

Commit 5a897aa

Browse files
SushisourceVegetarianOrcchrsmith
authored
Inline Nexus workflow ID formatting (#762)
* Inline Nexus workflow ID formatting * Fix wild newlines from codex * run formatter * Update core/src/main/java/io/temporal/samples/nexus/handler/SampleNexusServiceImpl.java Co-authored-by: Chris Smith <chrsmith@users.noreply.github.com> --------- Co-authored-by: Alex Mazzeo <alex.mazzeo@temporal.io> Co-authored-by: Alex Mazzeo <alex.mazzeo@outlook.com> Co-authored-by: Chris Smith <chrsmith@users.noreply.github.com>
1 parent 1fd2eef commit 5a897aa

3 files changed

Lines changed: 34 additions & 21 deletions

File tree

core/src/main/java/io/temporal/samples/nexus/handler/SampleNexusServiceImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.temporal.nexus.Nexus;
88
import io.temporal.nexus.WorkflowRunOperation;
99
import io.temporal.samples.nexus.service.SampleNexusService;
10+
import java.util.Locale;
1011

1112
// To create a service implementation, annotate the class with @ServiceImpl and provide the
1213
// interface that the service implements. The service implementation class should have methods that
@@ -55,13 +56,19 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
5556
.newWorkflowStub(
5657
HelloHandlerWorkflow.class,
5758
// Workflow IDs should typically be business meaningful IDs and are used to
58-
// dedupe workflow starts. For this example, we're using the request ID
59-
// allocated by Temporal when the caller workflow schedules
60-
// the operation, this ID is guaranteed to be stable across retries of this
61-
// operation.
59+
// dedupe workflow starts.
60+
//
61+
// For this example, tie the workflow ID to the customer being greeted so
62+
// that repeated operations for the same customer run on the same workflow.
6263
//
6364
// Task queue defaults to the task queue this operation is handled on.
64-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
65+
WorkflowOptions.newBuilder()
66+
.setWorkflowId(
67+
String.format(
68+
"hello-%s-%s",
69+
input.getName(),
70+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
71+
.build())
6572
::hello);
6673
}
6774
}

core/src/main/java/io/temporal/samples/nexuscontextpropagation/handler/SampleNexusServiceImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.temporal.nexus.WorkflowRunOperation;
99
import io.temporal.samples.nexus.handler.HelloHandlerWorkflow;
1010
import io.temporal.samples.nexus.service.SampleNexusService;
11+
import java.util.Locale;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
1314
import org.slf4j.MDC;
@@ -52,14 +53,18 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
5253
HelloHandlerWorkflow.class,
5354
// Workflow IDs should typically be business meaningful IDs and are used to
5455
// dedupe workflow starts.
55-
// For this example, we're using the request ID allocated by Temporal when
56-
// the
57-
// caller workflow schedules
58-
// the operation, this ID is guaranteed to be stable across retries of this
59-
// operation.
56+
//
57+
// For this example, tie the workflow ID to the customer being greeted so
58+
// that repeated operations for the same customer run on the same workflow.
6059
//
6160
// Task queue defaults to the task queue this operation is handled on.
62-
WorkflowOptions.newBuilder().setWorkflowId(details.getRequestId()).build())
61+
WorkflowOptions.newBuilder()
62+
.setWorkflowId(
63+
String.format(
64+
"hello-%s-%s",
65+
input.getName(),
66+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
67+
.build())
6368
::hello);
6469
}
6570
}

core/src/main/java/io/temporal/samples/nexusmultipleargs/handler/SampleNexusServiceImpl.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.temporal.nexus.WorkflowHandle;
99
import io.temporal.nexus.WorkflowRunOperation;
1010
import io.temporal.samples.nexus.service.SampleNexusService;
11+
import java.util.Locale;
1112

1213
// To create a service implementation, annotate the class with @ServiceImpl and provide the
1314
// interface that the service implements. The service implementation class should have methods that
@@ -39,19 +40,19 @@ public OperationHandler<SampleNexusService.HelloInput, SampleNexusService.HelloO
3940
.newWorkflowStub(
4041
HelloHandlerWorkflow.class,
4142
// Workflow IDs should typically be business meaningful IDs and are used
42-
// to
43-
// dedupe workflow starts.
44-
// For this example, we're using the request ID allocated by Temporal
45-
// when
46-
// the
47-
// caller workflow schedules
48-
// the operation, this ID is guaranteed to be stable across retries of
49-
// this
50-
// operation.
43+
// to dedupe workflow starts.
44+
//
45+
// For this example, tie the workflow ID to the customer being greeted
46+
// so that repeated operations for the same customer run on the same
47+
// workflow.
5148
//
5249
// Task queue defaults to the task queue this operation is handled on.
5350
WorkflowOptions.newBuilder()
54-
.setWorkflowId(details.getRequestId())
51+
.setWorkflowId(
52+
String.format(
53+
"hello-%s-%s",
54+
input.getName(),
55+
input.getLanguage().name().toLowerCase(Locale.ROOT)))
5556
.build())
5657
::hello,
5758
input.getName(),

0 commit comments

Comments
 (0)