Skip to content

Commit e3f4224

Browse files
committed
Fix NPE
Signed-off-by: siri-varma <siri.varma@outlook.com> Signed-off-by: sirivarma <siri.varma@outlook.com>
1 parent 81d8a22 commit e3f4224

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.dapr.workflows.client.DaprWorkflowClient;
1717
import io.dapr.workflows.client.WorkflowInstanceStatus;
1818

19+
import java.time.Duration;
1920
import java.util.concurrent.TimeoutException;
2021

2122
public class DemoChildWorkerflowClient {
@@ -27,15 +28,19 @@ public class DemoChildWorkerflowClient {
2728
*/
2829
public static void main(String[] args) {
2930
try (DaprWorkflowClient client = new DaprWorkflowClient()) {
30-
String instanceId = client.scheduleNewWorkflow(DemoWorkflow.class);
31+
String instanceId = client.scheduleNewWorkflow(DemoChildWorkflow.class, "Hello Word");
3132
System.out.printf("Started a new child-workflow model workflow with instance ID: %s%n", instanceId);
32-
WorkflowInstanceStatus workflowInstanceStatus =
33-
client.waitForInstanceCompletion(instanceId, null, true);
3433

35-
String result = workflowInstanceStatus.readOutputAs(String.class);
36-
System.out.printf("workflow instance with ID: %s completed with result: %s%n", instanceId, result);
34+
while (true) {
35+
try {
36+
Thread.sleep(10000);
37+
System.out.println(client.getInstanceState(instanceId, true).getRuntimeStatus());
38+
} catch (Exception ex) {
39+
System.out.println("exception");
40+
}
41+
}
3742

38-
} catch (TimeoutException | InterruptedException e) {
43+
} catch (InterruptedException e) {
3944
throw new RuntimeException(e);
4045
}
4146
}

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,41 @@
1313

1414
package io.dapr.examples.workflows.childworkflow;
1515

16+
import io.dapr.durabletask.interruption.OrchestratorBlockedException;
1617
import io.dapr.workflows.Workflow;
1718
import io.dapr.workflows.WorkflowStub;
19+
import io.dapr.workflows.WorkflowTaskOptions;
20+
import io.dapr.workflows.WorkflowTaskRetryPolicy;
21+
22+
import java.time.Duration;
1823

1924
public class DemoChildWorkflow implements Workflow {
2025
@Override
2126
public WorkflowStub create() {
2227
return ctx -> {
2328
ctx.getLogger().info("Starting ChildWorkflow: " + ctx.getName());
2429

30+
WorkflowTaskRetryPolicy policy = WorkflowTaskRetryPolicy.newBuilder()
31+
.setFirstRetryInterval(Duration.ofSeconds(1))
32+
.setMaxNumberOfAttempts(10)
33+
.build();
34+
35+
WorkflowTaskOptions options = new WorkflowTaskOptions(policy);
36+
2537
var childWorkflowInput = ctx.getInput(String.class);
2638
ctx.getLogger().info("ChildWorkflow received input: " + childWorkflowInput);
2739

2840
ctx.getLogger().info("ChildWorkflow is calling Activity: " + ReverseActivity.class.getName());
29-
String result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, String.class).await();
41+
String result = new String("");
42+
43+
try {
44+
result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, options, String.class).await();
45+
} catch (OrchestratorBlockedException ex) {
46+
throw ex;
47+
} catch (Exception ex) {
48+
System.out.println("EX:" + ex.getMessage());
49+
ctx.getLogger().warn("Ex is what instance of " + (ex.getMessage()));
50+
}
3051

3152
ctx.getLogger().info("ChildWorkflow finished with: " + result);
3253
ctx.complete(result);

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
package io.dapr.examples.workflows.childworkflow;
1515

16+
import io.dapr.workflows.WorkflowTaskRetryPolicy;
1617
import io.dapr.workflows.runtime.WorkflowRuntime;
1718
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
1819

20+
import java.time.Duration;
21+
import java.time.temporal.ChronoUnit;
22+
1923
public class DemoChildWorkflowWorker {
2024
/**
2125
* The main method of this app.
@@ -25,13 +29,15 @@ public class DemoChildWorkflowWorker {
2529
*/
2630
public static void main(String[] args) throws Exception {
2731
// Register the Workflow with the builder.
32+
2833
WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder()
2934
.registerWorkflow(DemoWorkflow.class)
3035
.registerWorkflow(DemoChildWorkflow.class);
3136
builder.registerActivity(ReverseActivity.class);
3237

3338
// Build and then start the workflow runtime pulling and executing tasks
3439
WorkflowRuntime runtime = builder.build();
40+
runtime.start();
3541
System.out.println("Start workflow runtime");
3642
}
3743
}

examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public Object run(WorkflowActivityContext ctx) {
3030
logger.info("Message Received from input: " + message);
3131
logger.info("Sending message to output: " + newMessage);
3232

33-
return newMessage;
33+
throw new RuntimeException("abcdef");
3434
}
3535
}
36+
37+
class MyCustomException extends RuntimeException {
38+
39+
public MyCustomException(String message) {
40+
super(message);
41+
}
42+
}

sdk-workflows/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>io.dapr</groupId>
4949
<artifactId>durabletask-client</artifactId>
50-
<version>1.5.2</version>
50+
<version>1.5.3</version>
5151
</dependency>
5252
<!--
5353
manually declare durabletask-client's jackson dependencies

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ public Builder setMaxRetryInterval(@Nullable Duration maxRetryInterval) {
166166
* @return This builder
167167
*/
168168
public Builder setRetryTimeout(Duration retryTimeout) {
169-
if (retryTimeout != null && retryTimeout.compareTo(this.firstRetryInterval) < 0) {
169+
if (retryTimeout == null || retryTimeout.compareTo(this.firstRetryInterval) < 0) {
170170
throw new IllegalArgumentException(
171-
"The value for retryTimeout must be greater than or equal to the value for firstRetryInterval.");
171+
"The value for retryTimeout cannot be null and"
172+
+ " must be greater than or equal to the value for firstRetryInterval.");
172173
}
173174

174175
this.retryTimeout = retryTimeout;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ private static TaskOptions toTaskOptions(WorkflowTaskOptions options) {
240240
);
241241

242242
retryPolicy.setBackoffCoefficient(workflowTaskRetryPolicy.getBackoffCoefficient());
243-
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
243+
if (workflowTaskRetryPolicy.getRetryTimeout() != null) {
244+
retryPolicy.setRetryTimeout(workflowTaskRetryPolicy.getRetryTimeout());
245+
}
244246

245247
return new TaskOptions(retryPolicy);
246248
}

0 commit comments

Comments
 (0)