Skip to content

Commit 85e0cac

Browse files
committed
chore: Introduce new task execution key
All Task will receive a task execution key that can be use for idempotency checks Signed-off-by: Javier Aliaga <[email protected]>
1 parent 5880cda commit 85e0cac

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

client/src/main/java/io/dapr/durabletask/DurableTaskGrpcWorker.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ public void startAndBlock() {
160160
String output = null;
161161
TaskFailureDetails failureDetails = null;
162162
try {
163+
String instanceId = activityRequest.getOrchestrationInstance().getInstanceId();
164+
String taskName = activityRequest.getName();
165+
String taskExecutionKey = instanceId + "-" + taskName;
163166
output = taskActivityExecutor.execute(
164167
activityRequest.getName(),
165168
activityRequest.getInput().getValue(),
166-
activityRequest.getTaskId());
169+
taskExecutionKey);
167170
} catch (Throwable e) {
168171
failureDetails = TaskFailureDetails.newBuilder()
169172
.setErrorType(e.getClass().getName())

client/src/main/java/io/dapr/durabletask/TaskActivityContext.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@
77
* its input.
88
*/
99
public interface TaskActivityContext {
10-
/**
11-
* Gets the name of the current task activity.
12-
* @return the name of the current task activity
13-
*/
14-
String getName();
10+
/**
11+
* Gets the name of the current task activity.
12+
* @return the name of the current task activity
13+
*/
14+
String getName();
15+
16+
/**
17+
* Gets the task execution key of the current task activity.
18+
* This key is used to identify the task execution and is unique for each task execution.
19+
* @return the task execution key of the current task activity
20+
*/
21+
String getTaskExecutionKey();
1522

1623
/**
1724
* Gets the deserialized activity input.

client/src/main/java/io/dapr/durabletask/TaskActivityExecutor.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public TaskActivityExecutor(
1919
this.logger = logger;
2020
}
2121

22-
public String execute(String taskName, String input, int taskId) throws Throwable {
22+
public String execute(String taskName, String input, String taskExecutionKey) throws Throwable {
2323
TaskActivityFactory factory = this.activityFactories.get(taskName);
2424
if (factory == null) {
2525
throw new IllegalStateException(
@@ -32,7 +32,7 @@ public String execute(String taskName, String input, int taskId) throws Throwabl
3232
String.format("The task factory '%s' returned a null TaskActivity object.", taskName));
3333
}
3434

35-
TaskActivityContextImpl context = new TaskActivityContextImpl(taskName, input);
35+
TaskActivityContextImpl context = new TaskActivityContextImpl(taskName, input, taskExecutionKey);
3636

3737
// Unhandled exceptions are allowed to escape
3838
Object output = activity.run(context);
@@ -44,21 +44,29 @@ public String execute(String taskName, String input, int taskId) throws Throwabl
4444
}
4545

4646
private class TaskActivityContextImpl implements TaskActivityContext {
47+
private final String taskExecutionKey;
4748
private final String name;
4849
private final String rawInput;
50+
4951

5052
private final DataConverter dataConverter = TaskActivityExecutor.this.dataConverter;
5153

52-
public TaskActivityContextImpl(String activityName, String rawInput) {
54+
public TaskActivityContextImpl(String activityName, String rawInput, String taskExecutionKey) {
5355
this.name = activityName;
5456
this.rawInput = rawInput;
57+
this.taskExecutionKey = taskExecutionKey;
5558
}
5659

5760
@Override
5861
public String getName() {
5962
return this.name;
6063
}
6164

65+
@Override
66+
public String getTaskExecutionKey() {
67+
return this.taskExecutionKey;
68+
}
69+
6270
@Override
6371
public <T> T getInput(Class<T> targetType) {
6472
if (this.rawInput == null) {

0 commit comments

Comments
 (0)