-
Notifications
You must be signed in to change notification settings - Fork 218
Adding Support for Suspend / Resume Workflows #1405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
959dc19
adding IT test
salaboy 49fad69
adding initial version of suspend/resume example
salaboy fa1a214
updating README
salaboy ef1d056
Update README.md
salaboy 1d3c9c0
following Javi's suggestion
salaboy 3713bef
fixing wrong year in headers
salaboy 3cce79c
fixing paths in one more README.md file
salaboy 71d51c0
adding output validation
salaboy ee89be9
adding missing port
salaboy 646268d
fixing check conditions
salaboy 77936d6
Merge branch 'master' into 1402-suspend-resume
cicoyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
examples/src/main/java/io/dapr/examples/workflows/suspendresume/DemoSuspendResumeClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.examples.workflows.suspendresume; | ||
|
||
import io.dapr.examples.workflows.externalevent.DemoExternalEventWorkflow; | ||
import io.dapr.workflows.client.DaprWorkflowClient; | ||
import io.dapr.workflows.client.WorkflowInstanceStatus; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
public class DemoSuspendResumeClient { | ||
/** | ||
* The main method to start the client. | ||
* | ||
* @param args Input arguments (unused). | ||
* @throws InterruptedException If program has been interrupted. | ||
*/ | ||
public static void main(String[] args) { | ||
try (DaprWorkflowClient client = new DaprWorkflowClient()) { | ||
String instanceId = client.scheduleNewWorkflow(DemoExternalEventWorkflow.class); | ||
System.out.printf("Started a new external-event workflow with instance ID: %s%n", instanceId); | ||
|
||
|
||
System.out.printf("Suspending Workflow Instance: %s%n", instanceId ); | ||
client.suspendWorkflow(instanceId, "suspending workflow instance."); | ||
|
||
WorkflowInstanceStatus instanceState = client.getInstanceState(instanceId, false); | ||
assert instanceState != null; | ||
System.out.printf("Workflow Instance Status: %s%n", instanceState.getRuntimeStatus().name() ); | ||
|
||
System.out.printf("Let's resume the Workflow Instance before sending the external event: %s%n", instanceId ); | ||
client.resumeWorkflow(instanceId, "resuming workflow instance."); | ||
|
||
instanceState = client.getInstanceState(instanceId, false); | ||
assert instanceState != null; | ||
System.out.printf("Workflow Instance Status: %s%n", instanceState.getRuntimeStatus().name() ); | ||
|
||
System.out.printf("Now that the instance is RUNNING again, lets send the external event. %n"); | ||
client.raiseEvent(instanceId, "Approval", true); | ||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
client.waitForInstanceCompletion(instanceId, null, true); | ||
System.out.printf("workflow instance with ID: %s completed.", instanceId); | ||
|
||
} catch (TimeoutException | InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
examples/src/main/java/io/dapr/examples/workflows/suspendresume/DemoSuspendResumeWorker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2025 The Dapr Authors | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.dapr.examples.workflows.suspendresume; | ||
|
||
import io.dapr.examples.workflows.externalevent.ApproveActivity; | ||
import io.dapr.examples.workflows.externalevent.DemoExternalEventWorkflow; | ||
import io.dapr.examples.workflows.externalevent.DenyActivity; | ||
import io.dapr.workflows.runtime.WorkflowRuntime; | ||
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder; | ||
|
||
public class DemoSuspendResumeWorker { | ||
/** | ||
* The main method of this app. | ||
* | ||
* @param args The port the app will listen on. | ||
* @throws Exception An Exception. | ||
*/ | ||
public static void main(String[] args) throws Exception { | ||
// Register the Workflow with the builder. | ||
WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder().registerWorkflow(DemoExternalEventWorkflow.class); | ||
builder.registerActivity(ApproveActivity.class); | ||
builder.registerActivity(DenyActivity.class); | ||
|
||
// Build and then start the workflow runtime pulling and executing tasks | ||
WorkflowRuntime runtime = builder.build(); | ||
System.out.println("Start workflow runtime"); | ||
runtime.start(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.