Skip to content

Commit 31c07ae

Browse files
committed
add support for custom status
1 parent 04b19e1 commit 31c07ae

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowContext.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,12 @@ default void continueAsNew(Object input) {
526526
default UUID newUuid() {
527527
throw new RuntimeException("No implementation found.");
528528
}
529+
530+
/**
531+
* Set a custom status to a workflow execution.
532+
*
533+
* @param status to be set to the current execution
534+
*/
535+
void setCustomStatus(Object status);
536+
529537
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/DefaultWorkflowContext.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public DefaultWorkflowContext(TaskOrchestrationContext context) throws IllegalAr
5959
* @throws IllegalArgumentException if context or logger is null
6060
*/
6161
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger)
62-
throws IllegalArgumentException {
62+
throws IllegalArgumentException {
6363
if (context == null) {
6464
throw new IllegalArgumentException("Context cannot be null");
6565
}
@@ -114,7 +114,7 @@ public void complete(Object output) {
114114
*/
115115
@Override
116116
public <V> Task<V> waitForExternalEvent(String name, Duration timeout, Class<V> dataType)
117-
throws TaskCanceledException {
117+
throws TaskCanceledException {
118118
return this.innerContext.waitForExternalEvent(name, timeout, dataType);
119119
}
120120

@@ -130,7 +130,7 @@ public <V> Task<V> waitForExternalEvent(String name, Duration timeout, Class<V>
130130
* @param timeout the amount of time to wait before canceling the returned
131131
* {@code Task}
132132
* @return a new {@link Task} that completes when the external event is received
133-
* or when {@code timeout} expires
133+
* or when {@code timeout} expires
134134
* @throws TaskCanceledException if the specified {@code timeout} value expires
135135
* before the event is received
136136
*/
@@ -294,4 +294,13 @@ private RetryHandler toRetryHandler(WorkflowTaskRetryHandler workflowTaskRetryHa
294294
return workflowTaskRetryHandler.handle(workflowRetryContext);
295295
};
296296
}
297+
298+
/**
299+
* Set custom status to a workflow execution.
300+
*
301+
* @param status to set to the execution
302+
*/
303+
public void setCustomStatus(Object status) {
304+
innerContext.setCustomStatus(status);
305+
}
297306
}

sdk-workflows/src/test/java/io/dapr/workflows/DefaultWorkflowContextTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public <V> Task<V> callChildWorkflow(String name, @Nullable Object input, @Nulla
135135
@Override
136136
public void continueAsNew(Object input, boolean preserveUnprocessedEvents) {
137137
}
138+
139+
@Override
140+
public void setCustomStatus(Object status) {
141+
142+
}
138143
};
139144
}
140145

@@ -403,6 +408,15 @@ public void callChildWorkflow() {
403408
verify(mockInnerContext, times(1)).callSubOrchestrator(expectedName, expectedInput, null, null, String.class);
404409
}
405410

411+
@Test
412+
public void setCustomStatusWorkflow() {
413+
String customStatus = "CustomStatus";
414+
415+
context.setCustomStatus(customStatus);
416+
verify(mockInnerContext, times(1)).setCustomStatus(customStatus);
417+
418+
}
419+
406420
@Test
407421
public void newUuidTest() {
408422
context.newUuid();

0 commit comments

Comments
 (0)