Skip to content

Commit 8a4c68b

Browse files
committed
refactor: apply pull request suggestions
Signed-off-by: Matheus Cruz <[email protected]>
1 parent a7d426a commit 8a4c68b

File tree

6 files changed

+378
-1
lines changed

6 files changed

+378
-1
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/client/DaprWorkflowClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public void raiseEvent(String workflowInstanceId, String eventName, Object event
244244
* @param workflowInstanceId The unique ID of the workflow instance to purge.
245245
* @return Return true if the workflow state was found and purged successfully otherwise false.
246246
*/
247+
@Deprecated(forRemoval = true)
247248
public boolean purgeInstance(String workflowInstanceId) {
248249
PurgeResult result = this.innerClient.purgeInstance(workflowInstanceId);
249250

@@ -254,6 +255,23 @@ public boolean purgeInstance(String workflowInstanceId) {
254255
return false;
255256
}
256257

258+
/**
259+
* Purges workflow instance state from the workflow state store.
260+
*
261+
* @param workflowInstanceId The unique ID of the workflow instance to purge.
262+
* @return Return true if the workflow state was found and purged successfully otherwise false.
263+
*/
264+
public boolean purgeWorkflow(String workflowInstanceId) {
265+
PurgeResult result = this.innerClient.purgeInstance(workflowInstanceId);
266+
267+
if (result != null) {
268+
return result.getDeletedInstanceCount() > 0;
269+
}
270+
271+
return false;
272+
}
273+
274+
257275
/**
258276
* Closes the inner DurableTask client and shutdown the GRPC channel.
259277
*/

sdk-workflows/src/main/java/io/dapr/workflows/client/WorkflowInstanceStatus.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
/**
2121
* Represents a snapshot of a workflow instance's current state, including
2222
* metadata.
23+
*
24+
* @deprecated Use {@link WorkflowState} instead.
2325
*/
26+
@Deprecated(forRemoval = true)
2427
public interface WorkflowInstanceStatus {
2528

2629
/**
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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.workflows.client;
15+
16+
import javax.annotation.Nullable;
17+
18+
import java.time.Instant;
19+
20+
/**
21+
* Represents a snapshot of a workflow instance's current state, including
22+
* metadata.
23+
*/
24+
public interface WorkflowState {
25+
26+
/**
27+
* Gets the name of the workflow.
28+
*
29+
* @return the name of the workflow
30+
*/
31+
String getName();
32+
33+
/**
34+
* Gets the unique ID of the workflow instance.
35+
*
36+
* @return the unique ID of the workflow instance
37+
*/
38+
String getWorkflowId();
39+
40+
/**
41+
* Gets the current runtime status of the workflow instance at the time this
42+
* object was fetched.
43+
*
44+
* @return the current runtime status of the workflow instance at the time this object was fetched
45+
*/
46+
WorkflowRuntimeStatus getRuntimeStatus();
47+
48+
/**
49+
* Gets the workflow instance's creation time in UTC.
50+
*
51+
* @return the workflow instance's creation time in UTC
52+
*/
53+
Instant getCreatedAt();
54+
55+
/**
56+
* Gets the workflow instance's last updated time in UTC.
57+
*
58+
* @return the workflow instance's last updated time in UTC
59+
*/
60+
Instant getLastUpdatedAt();
61+
62+
/**
63+
* Gets the workflow instance's serialized input, if any, as a string value.
64+
*
65+
* @return the workflow instance's serialized input or {@code null}
66+
*/
67+
String getSerializedInput();
68+
69+
/**
70+
* Gets the workflow instance's serialized output, if any, as a string value.
71+
*
72+
* @return the workflow instance's serialized output or {@code null}
73+
*/
74+
String getSerializedOutput();
75+
76+
/**
77+
* Gets the failure details, if any, for the failed workflow instance.
78+
*
79+
* <p>This method returns data only if the workflow is in the
80+
* {@link WorkflowFailureDetails} failureDetails,
81+
* and only if this instance metadata was fetched with the option to include
82+
* output data.
83+
*
84+
* @return the failure details of the failed workflow instance or {@code null}
85+
*/
86+
@Nullable
87+
WorkflowFailureDetails getFailureDetails();
88+
89+
/**
90+
* Gets a value indicating whether the workflow instance was running at the time
91+
* this object was fetched.
92+
*
93+
* @return {@code true} if the workflow existed and was in a running state otherwise {@code false}
94+
*/
95+
boolean isRunning();
96+
97+
/**
98+
* Gets a value indicating whether the workflow instance was completed at the
99+
* time this object was fetched.
100+
*
101+
* <p>A workflow instance is considered completed when its runtime status value is
102+
* {@link WorkflowRuntimeStatus#COMPLETED},
103+
* {@link WorkflowRuntimeStatus#FAILED}, or
104+
* {@link WorkflowRuntimeStatus#TERMINATED}.
105+
*
106+
* @return {@code true} if the workflow was in a terminal state; otherwise {@code false}
107+
*/
108+
boolean isCompleted();
109+
110+
/**
111+
* Deserializes the workflow's input into an object of the specified type.
112+
*
113+
* <p>Deserialization is performed using the DataConverter that was
114+
* configured on the DurableTaskClient object that created this workflow
115+
* metadata object.
116+
*
117+
* @param type the class associated with the type to deserialize the input data
118+
* into
119+
* @param <T> the type to deserialize the input data into
120+
* @return the deserialized input value
121+
* @throws IllegalStateException if the metadata was fetched without the option
122+
* to read inputs and outputs
123+
*/
124+
<T> T readInputAs(Class<T> type);
125+
126+
/**
127+
* Deserializes the workflow's output into an object of the specified type.
128+
*
129+
* <p>Deserialization is performed using the DataConverter that was
130+
* configured on the DurableTaskClient
131+
* object that created this workflow metadata object.
132+
*
133+
* @param type the class associated with the type to deserialize the output data
134+
* into
135+
* @param <T> the type to deserialize the output data into
136+
* @return the deserialized input value
137+
* @throws IllegalStateException if the metadata was fetched without the option
138+
* to read inputs and outputs
139+
*/
140+
<T> T readOutputAs(Class<T> type);
141+
142+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
/**
2828
* Represents a snapshot of a workflow instance's current state, including
2929
* metadata.
30+
*
31+
* @deprecated Use {@link DefaultWorkflowState} instead.
3032
*/
33+
@Deprecated(forRemoval = true)
3134
public class DefaultWorkflowInstanceStatus implements WorkflowInstanceStatus {
3235

3336
private final OrchestrationMetadata orchestrationMetadata;

0 commit comments

Comments
 (0)