Skip to content

Commit 056aed4

Browse files
macromaniaLionTaomukundansundarartursouzadependabot[bot]
authored
Workflow Implementation - Continues... (dapr#880)
* Add ElementType.Type to ActorType (dapr#812) Signed-off-by: LionTao <[email protected]> Signed-off-by: LionTao <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Co-authored-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Bump codecov/codecov-action from 3.1.0 to 3.1.1 (dapr#788) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/master/CHANGELOG.md) - [Commits](codecov/codecov-action@v3.1.0...v3.1.1) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Update springboot to latest minor.patch version. (dapr#826) Signed-off-by: Mahmut Canga <[email protected]> * Use runtime 1.10.0-rc.X and CLI 1.10.0-rc.X (dapr#827) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Upgrade the version to 1.9.0-SNAPSHOT (dapr#829) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Generate updated javadocs for 1.8.0 (dapr#836) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Update Dapr runtime and CLI to 1.10. (dapr#837) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Inject autoconfiguration in the Spring Boot 3 style (dapr#831) * Bump from spring boot 2.3.5.RELEASE to 2.7.8 Signed-off-by: Sergio <[email protected]> (cherry picked from commit 9152c91) * Ensure old versions of spring boot are still compatible Signed-off-by: Sergio <[email protected]> --------- Signed-off-by: champel <[email protected]> Signed-off-by: Sergio <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Bump from reactor 2.3.5.RELEASE to 2.7.8 (dapr#830) * Bump from reactor 2.3.5.RELEASE to 2.7.8 Signed-off-by: Sergio <[email protected]> * Simplification Signed-off-by: Sergio <[email protected]> --------- Signed-off-by: Sergio <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Test multiple reminder state types + improve timer tests. (dapr#855) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Convert Config API to Stable endpoints. (dapr#846) Signed-off-by: Mahmut Canga <[email protected]> * Add PubSub subscriber examples over gPRC (dapr#833) * add grpc subscriber Signed-off-by: MregXN <[email protected]> * modify README.md Signed-off-by: MregXN <[email protected]> * modify README.md in examples Signed-off-by: MregXN <[email protected]> * Modify DaprApplication to support examples where protocol is not specified. Signed-off-by: MregXN <[email protected]> * modify formatter to pass checkstyle Signed-off-by: MregXN <[email protected]> * Update springboot to latest minor.patch version. (dapr#826) Signed-off-by: MregXN <[email protected]> * Use runtime 1.10.0-rc.X and CLI 1.10.0-rc.X (dapr#827) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: MregXN <[email protected]> * Upgrade the version to 1.9.0-SNAPSHOT (dapr#829) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: MregXN <[email protected]> * Generate updated javadocs for 1.8.0 (dapr#836) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: MregXN <[email protected]> * Update Dapr runtime and CLI to 1.10. (dapr#837) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: MregXN <[email protected]> * Inject autoconfiguration in the Spring Boot 3 style (dapr#831) * Bump from spring boot 2.3.5.RELEASE to 2.7.8 Signed-off-by: Sergio <[email protected]> (cherry picked from commit 9152c91) * Ensure old versions of spring boot are still compatible Signed-off-by: Sergio <[email protected]> --------- Signed-off-by: champel <[email protected]> Signed-off-by: Sergio <[email protected]> Signed-off-by: MregXN <[email protected]> * Bump from reactor 2.3.5.RELEASE to 2.7.8 (dapr#830) * Bump from reactor 2.3.5.RELEASE to 2.7.8 Signed-off-by: Sergio <[email protected]> * Simplification Signed-off-by: Sergio <[email protected]> --------- Signed-off-by: Sergio <[email protected]> Signed-off-by: MregXN <[email protected]> * rerun checks Signed-off-by: MregXN <[email protected]> * modify the way of grpc server starts Signed-off-by: MregXN <[email protected]> * modify README Signed-off-by: MregXN <[email protected]> * Update pom.xml Signed-off-by: MregXN <[email protected]> --------- Signed-off-by: MregXN <[email protected]> Signed-off-by: Artur Souza <[email protected]> Signed-off-by: champel <[email protected]> Signed-off-by: Sergio <[email protected]> Signed-off-by: MregXN <[email protected]> Co-authored-by: Artur Souza <[email protected]> Co-authored-by: champel <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * auto validate actors (dapr#863) Signed-off-by: Mukundan Sundararajan <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Bump codecov/codecov-action from 3.1.1 to 3.1.4 (dapr#862) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.1 to 3.1.4. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](codecov/codecov-action@v3.1.1...v3.1.4) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Mahmut Canga <[email protected]> * Fix 787 (dapr#832) * prepare before testing * Update tests * fix checkstyle --------- Co-authored-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Upgrade to 1.11 RCs. (dapr#867) Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Init for workflows Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Updating some javadocs and Years. Signed-off-by: Hannah Kennedy <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Add missing Header Signed-off-by: Hannah Kennedy <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * respond to PR feedback Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Update workflow example README Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Address PR feedback Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * fixup deprecated pom.xml variable Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Updates based on PR feedback Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Update pom files per feedback Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * GetInstanceState implementation (dapr#1) * addiny getInstanceMetadata, waitForInstanceStart and waitForInstanceCompletion implementation --------- Co-authored-by: aymanmahmoud_microsoft <[email protected]> Signed-off-by: Aymand Mahmoud <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Management API Signed-off-by: Mahmut Canga <[email protected]> * remove try/catch Signed-off-by: Mahmut Canga <[email protected]> * implementing getIsReplaying() method for Authoring API (dapr#7) Co-authored-by: Julio Rezende <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Signed-off-by: Julio Rezende <[email protected]> * Implementing getCurrentInstant() authoring method (dapr#5) Co-authored-by: Julio Rezende <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Signed-off-by: Julio Rezende <[email protected]> * Activity Implementation (dapr#3) Signed-off-by: Mahmut Canga <[email protected]> * fixing issue with getIsReplaying() call (dapr#8) Co-authored-by: Julio Rezende <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Signed-off-by: Julio Rezende <[email protected]> * Generate updated javadocs for 1.9.0 (dapr#878) * Generate updated javadocs for 1.9.0 Signed-off-by: Artur Souza <[email protected]> * Update _index.md Signed-off-by: Artur Souza <[email protected]> --------- Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Add .sdkmanrc config file and JDK installation instructions (dapr#873) * Add .sdkmanrc file with installation instructions Signed-off-by: Emanuel Alves <[email protected]> * Update README.md Signed-off-by: Artur Souza <[email protected]> --------- Signed-off-by: Emanuel Alves <[email protected]> Signed-off-by: Artur Souza <[email protected]> Co-authored-by: Artur Souza <[email protected]> Co-authored-by: Artur Souza <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Add unit testing example Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * implementing getIsReplaying() method for Authoring API (dapr#7) Co-authored-by: Julio Rezende <[email protected]> Signed-off-by: Julio Rezende <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * fix parent pom Signed-off-by: Mahmut Canga <[email protected]> * Send Event Implementation (dapr#10) Signed-off-by: Mahmut Canga <[email protected]> * Implementing allOf, anyOf, createTimer methods (dapr#11) Co-authored-by: Julio Rezende <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Co-authored-by: Julio Rezende <[email protected]> * Support remote endpoint. (dapr#877) * Support remote endpoint. Signed-off-by: Artur Souza <[email protected]> * Use GRPC_ENDPOINT and HTTP_ENDPOINT in integration tests. Signed-off-by: Artur Souza <[email protected]> * Fix happy path for waiting for sidecar test. Signed-off-by: Artur Souza <[email protected]> --------- Signed-off-by: Artur Souza <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * Add callSubWorkflow Implementation Co-authored-by: Aymand Mahmoud <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Signed-off-by: Aymand Mahmoud <[email protected]> * rename DemoSubWorkflow Co-authored-by: Aymand Mahmoud <[email protected]> Signed-off-by: Aymand Mahmoud <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * continueAsNew Implementation (dapr#13) Signed-off-by: Mahmut Canga <[email protected]> * remove duplicate class Signed-off-by: Mahmut Canga <[email protected]> * add missing mockito test dependency Signed-off-by: Mahmut Canga <[email protected]> * use new workflow client implementation Signed-off-by: Mahmut Canga <[email protected]> * moved implementations to new workflow and context Signed-off-by: Mahmut Canga <[email protected]> * relocate duplicate implemantation Signed-off-by: Mahmut Canga <[email protected]> * remove duplicate test and increase test coverage Signed-off-by: Mahmut Canga <[email protected]> * Implement retry and timeout policy for gRPC client. (dapr#889) * Implement retry and timeout policy for gRPC client. Signed-off-by: Artur Souza <[email protected]> * Fix invoke actor after aborted flow. Signed-off-by: Artur Souza <[email protected]> --------- Signed-off-by: Artur Souza <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> * renamed getIsReplaying Signed-off-by: Mahmut Canga <[email protected]> * rollback changes on client Signed-off-by: Mahmut Canga <[email protected]> * move workflow runtime state package Signed-off-by: Mahmut Canga <[email protected]> * rename workflow instance state to status Signed-off-by: Mahmut Canga <[email protected]> * remove unnecessary else Signed-off-by: Mahmut Canga <[email protected]> * removed unknown state Signed-off-by: Mahmut Canga <[email protected]> * updated comment Signed-off-by: Mahmut Canga <[email protected]> * updated workflow failure details Signed-off-by: Mahmut Canga <[email protected]> * fix style issues Signed-off-by: Mahmut Canga <[email protected]> * rollback merge change Signed-off-by: Mahmut Canga <[email protected]> * fixed pom files Signed-off-by: Mahmut Canga <[email protected]> * rollback actors pom changes on autoformat Signed-off-by: Mahmut Canga <[email protected]> * fixe actors pom Signed-off-by: Mahmut Canga <[email protected]> * fix styling on actors pom Signed-off-by: Mahmut Canga <[email protected]> * fix pom spacing Signed-off-by: Mahmut Canga <[email protected]> * move test to match the package Signed-off-by: Mahmut Canga <[email protected]> * add missing dependencies Signed-off-by: Mahmut Canga <[email protected]> * increased test coverage Signed-off-by: Mahmut Canga <[email protected]> * moved workflow runtime package Signed-off-by: Mahmut Canga <[email protected]> * add exception for missing case Signed-off-by: Mahmut Canga <[email protected]> * add null check for metadata Signed-off-by: Mahmut Canga <[email protected]> * add runtime exception error messages Signed-off-by: Mahmut Canga <[email protected]> * update try catch scope Signed-off-by: Mahmut Canga <[email protected]> * update activity definition to an interface Signed-off-by: Mahmut Canga <[email protected]> * update comments Signed-off-by: Mahmut Canga <[email protected]> * removed redundant method Signed-off-by: Mahmut Canga <[email protected]> * PR updates Signed-off-by: Mahmut Canga <[email protected]> --------- Signed-off-by: LionTao <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Artur Souza <[email protected]> Signed-off-by: champel <[email protected]> Signed-off-by: Sergio <[email protected]> Signed-off-by: MregXN <[email protected]> Signed-off-by: MregXN <[email protected]> Signed-off-by: Mukundan Sundararajan <[email protected]> Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Hannah Kennedy <[email protected]> Signed-off-by: Bill DeRusha <[email protected]> Signed-off-by: Aymand Mahmoud <[email protected]> Signed-off-by: Julio Rezende <[email protected]> Signed-off-by: Emanuel Alves <[email protected]> Signed-off-by: Mahmut Canga <[email protected]> Co-authored-by: LionTao <[email protected]> Co-authored-by: Mukundan Sundararajan <[email protected]> Co-authored-by: Artur Souza <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: champel <[email protected]> Co-authored-by: MregXN <[email protected]> Co-authored-by: MatejNedic <[email protected]> Co-authored-by: Bill DeRusha <[email protected]> Co-authored-by: Hannah Kennedy <[email protected]> Co-authored-by: Bill DeRusha <[email protected]> Co-authored-by: Aymalla <[email protected]> Co-authored-by: aymanmahmoud_microsoft <[email protected]> Co-authored-by: swetakumari <[email protected]> Co-authored-by: julio <[email protected]> Co-authored-by: Julio Rezende <[email protected]> Co-authored-by: Emanuel Alves <[email protected]> Co-authored-by: Artur Souza <[email protected]>
1 parent 85ffe8e commit 056aed4

28 files changed

+2286
-95
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.workflows;
15+
16+
public class DemoActivityInput {
17+
18+
private String message;
19+
20+
public DemoActivityInput() {
21+
}
22+
23+
public DemoActivityInput(String message) {
24+
this.message = message;
25+
}
26+
27+
public String getMessage() {
28+
return message;
29+
}
30+
31+
public void setMessage(String message) {
32+
this.message = message;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.workflows;
15+
16+
public class DemoActivityOutput {
17+
18+
private String originalMessage;
19+
private String newMessage;
20+
21+
public DemoActivityOutput() {
22+
}
23+
24+
public DemoActivityOutput(String originalMessage, String newMessage) {
25+
this.originalMessage = originalMessage;
26+
this.newMessage = newMessage;
27+
}
28+
29+
public String getOriginalMessage() {
30+
return originalMessage;
31+
}
32+
33+
public void setOriginalMessage(String originalMessage) {
34+
this.originalMessage = originalMessage;
35+
}
36+
37+
public String getNewMessage() {
38+
return newMessage;
39+
}
40+
41+
public void setNewMessage(String newMessage) {
42+
this.newMessage = newMessage;
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.workflows;
15+
16+
import io.dapr.workflows.Workflow;
17+
import io.dapr.workflows.WorkflowStub;
18+
19+
/**
20+
* Implementation of the DemoWorkflow for the server side.
21+
*/
22+
public class DemoSubWorkflow extends Workflow {
23+
@Override
24+
public WorkflowStub create() {
25+
return ctx -> {
26+
27+
var logger = ctx.getLogger();
28+
logger.info("Child-Workflow> Started: " + ctx.getName());
29+
logger.info("Child-Workflow> Instance ID: " + ctx.getInstanceId());
30+
logger.info("Child-Workflow> Current Time: " + ctx.getCurrentInstant());
31+
32+
var input = ctx.getInput(String.class);
33+
logger.info("Child-Workflow> Input: " + input);
34+
35+
logger.info("Child-Workflow> Completed");
36+
ctx.complete("result: " + input);
37+
};
38+
}
39+
}

examples/src/main/java/io/dapr/examples/workflows/DemoWorkflow.java

+88-5
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,114 @@
1313

1414
package io.dapr.examples.workflows;
1515

16+
import com.microsoft.durabletask.CompositeTaskFailedException;
17+
import com.microsoft.durabletask.Task;
1618
import com.microsoft.durabletask.TaskCanceledException;
1719
import io.dapr.workflows.Workflow;
1820
import io.dapr.workflows.WorkflowStub;
1921

2022
import java.time.Duration;
23+
import java.util.Arrays;
24+
import java.util.List;
2125

2226
/**
2327
* Implementation of the DemoWorkflow for the server side.
2428
*/
2529
public class DemoWorkflow extends Workflow {
26-
2730
@Override
2831
public WorkflowStub create() {
2932
return ctx -> {
3033
ctx.getLogger().info("Starting Workflow: " + ctx.getName());
3134
ctx.getLogger().info("Instance ID: " + ctx.getInstanceId());
32-
ctx.getLogger().info("Waiting for event: 'myEvent'...");
35+
ctx.getLogger().info("Current Orchestration Time: " + ctx.getCurrentInstant());
36+
ctx.getLogger().info("Waiting for event: 'TimedOutEvent'...");
37+
try {
38+
ctx.waitForExternalEvent("TimedOutEvent", Duration.ofSeconds(10)).await();
39+
} catch (TaskCanceledException e) {
40+
ctx.getLogger().warn("Timed out");
41+
ctx.getLogger().warn(e.getMessage());
42+
}
43+
44+
ctx.getLogger().info("Waiting for event: 'TestEvent'...");
45+
try {
46+
ctx.waitForExternalEvent("TestEvent", Duration.ofSeconds(10)).await();
47+
ctx.getLogger().info("Received TestEvent");
48+
} catch (TaskCanceledException e) {
49+
ctx.getLogger().warn("Timed out");
50+
ctx.getLogger().warn(e.getMessage());
51+
}
52+
53+
ctx.getLogger().info("Parallel Execution - Waiting for all tasks to finish...");
54+
try {
55+
Task<String> t1 = ctx.waitForExternalEvent("event1", Duration.ofSeconds(5), String.class);
56+
Task<String> t2 = ctx.waitForExternalEvent("event2", Duration.ofSeconds(5), String.class);
57+
Task<String> t3 = ctx.waitForExternalEvent("event3", Duration.ofSeconds(5), String.class);
58+
59+
List<String> results = ctx.allOf(Arrays.asList(t1, t2, t3)).await();
60+
results.forEach(t -> ctx.getLogger().info("finished task: " + t));
61+
ctx.getLogger().info("All tasks finished!");
62+
63+
} catch (CompositeTaskFailedException e) {
64+
ctx.getLogger().warn(e.getMessage());
65+
List<Exception> exceptions = e.getExceptions();
66+
exceptions.forEach(ex -> ctx.getLogger().warn(ex.getMessage()));
67+
}
68+
69+
ctx.getLogger().info("Parallel Execution - Waiting for any task to finish...");
3370
try {
34-
ctx.waitForExternalEvent("myEvent", Duration.ofSeconds(10)).await();
35-
ctx.getLogger().info("Received!");
71+
Task<String> e1 = ctx.waitForExternalEvent("e1", Duration.ofSeconds(5), String.class);
72+
Task<String> e2 = ctx.waitForExternalEvent("e2", Duration.ofSeconds(5), String.class);
73+
Task<String> e3 = ctx.waitForExternalEvent("e3", Duration.ofSeconds(5), String.class);
74+
Task<Void> timeoutTask = ctx.createTimer(Duration.ofSeconds(1));
75+
76+
Task<?> winner = ctx.anyOf(Arrays.asList(e1, e2, e3, timeoutTask)).await();
77+
if (winner == timeoutTask) {
78+
ctx.getLogger().info("All tasks timed out!");
79+
} else {
80+
ctx.getLogger().info("One of the tasks finished!");
81+
}
3682
} catch (TaskCanceledException e) {
3783
ctx.getLogger().warn("Timed out");
3884
ctx.getLogger().warn(e.getMessage());
3985
}
40-
ctx.complete("finished");
86+
87+
ctx.getLogger().info("Calling Activity...");
88+
var input = new DemoActivityInput("Hello Activity!");
89+
var output = ctx.callActivity(DemoWorkflowActivity.class.getName(), input, DemoActivityOutput.class).await();
90+
91+
ctx.getLogger().info("Activity returned: " + output);
92+
ctx.getLogger().info("Activity returned: " + output.getNewMessage());
93+
ctx.getLogger().info("Activity returned: " + output.getOriginalMessage());
94+
95+
96+
boolean shouldComplete = true;
97+
ctx.getLogger().info("Waiting for event: 'RestartEvent'...");
98+
try {
99+
ctx.waitForExternalEvent("RestartEvent", Duration.ofSeconds(10)).await();
100+
ctx.getLogger().info("Received RestartEvent");
101+
ctx.getLogger().info("Restarting Workflow by calling continueAsNew...");
102+
ctx.continueAsNew("TestInputRestart", false);
103+
shouldComplete = false;
104+
} catch (TaskCanceledException e) {
105+
ctx.getLogger().warn("Restart Timed out");
106+
ctx.getLogger().warn(e.getMessage());
107+
}
108+
109+
if (shouldComplete) {
110+
ctx.getLogger().info("Child-Workflow> Calling ChildWorkflow...");
111+
var childWorkflowInput = "Hello ChildWorkflow!";
112+
var childWorkflowOutput =
113+
ctx.callSubWorkflow(DemoSubWorkflow.class.getName(), childWorkflowInput, String.class).await();
114+
115+
ctx.getLogger().info("Child-Workflow> returned: " + childWorkflowOutput);
116+
117+
ctx.getLogger().info("Workflow finished");
118+
ctx.complete("finished");
119+
120+
return;
121+
}
122+
123+
ctx.getLogger().info("Workflow restarted");
41124
};
42125
}
43126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.workflows;
15+
16+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
17+
import io.dapr.workflows.runtime.WorkflowActivity;
18+
import io.dapr.workflows.runtime.WorkflowActivityContext;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
import java.util.concurrent.TimeUnit;
23+
24+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
25+
public class DemoWorkflowActivity implements WorkflowActivity {
26+
27+
@Override
28+
public DemoActivityOutput run(WorkflowActivityContext ctx) {
29+
Logger logger = LoggerFactory.getLogger(DemoWorkflowActivity.class);
30+
logger.info("Starting Activity: " + ctx.getName());
31+
32+
var message = ctx.getInput(DemoActivityInput.class).getMessage();
33+
var newMessage = message + " World!, from Activity";
34+
logger.info("Message Received from input: " + message);
35+
logger.info("Sending message to output: " + newMessage);
36+
37+
logger.info("Sleeping for 5 seconds to simulate long running operation...");
38+
39+
try {
40+
TimeUnit.SECONDS.sleep(5);
41+
} catch (InterruptedException e) {
42+
throw new RuntimeException(e);
43+
}
44+
45+
46+
logger.info("Activity finished");
47+
48+
var output = new DemoActivityOutput(message, newMessage);
49+
logger.info("Activity returned: " + output);
50+
51+
return output;
52+
}
53+
}

0 commit comments

Comments
 (0)