22
33import io .iworkflow .core .mapper .StateMovementMapper ;
44import io .iworkflow .core .persistence .PersistenceOptions ;
5+ import io .iworkflow .gen .models .ErrorSubStatus ;
56import io .iworkflow .gen .models .ExecuteApiFailurePolicy ;
67import io .iworkflow .gen .models .KeyValue ;
78import io .iworkflow .gen .models .SearchAttribute ;
@@ -251,16 +252,38 @@ private List<SearchAttribute> convertToSearchAttributeList(final Map<String, Sea
251252 }
252253
253254 /**
255+ * A long poll API to wait for the workflow completion
256+ * If the workflow is not COMPLETED, throw the {@link WorkflowUncompletedException}.
257+ *
258+ * @param workflowId required, the workflowId
259+ */
260+ public void waitForWorkflowCompletion (
261+ final String workflowId ) {
262+ this .getSimpleWorkflowResultWithWait (Void .class , workflowId );
263+ }
264+
265+ /**
266+ * A long poll API to wait for the workflow completion
254267 * For most cases, a workflow only has one result(one completion state).
255268 * Use this API to retrieve the output of the state with waiting for the workflow to complete.
256- * If the workflow is not COMPLETED, throw the {@link feign.FeignException.FeignClientException }.
269+ * If the workflow is not COMPLETED, throw the {@link WorkflowUncompletedException }.
257270 *
258271 * @param valueClass required, the type class of the output
259272 * @param workflowId required, the workflowId
260- * @param workflowRunId optional, can be empty
261273 * @param <T> type of the output
262274 * @return the output result
263275 */
276+ public <T > T waitForWorkflowCompletion (
277+ final Class <T > valueClass ,
278+ final String workflowId ) {
279+ return this .getSimpleWorkflowResultWithWait (valueClass , workflowId );
280+ }
281+
282+ /**
283+ * Use {@link #waitForWorkflowCompletion(Class, String)} instead
284+ * It's just a renaming.
285+ */
286+ @ Deprecated
264287 public <T > T getSimpleWorkflowResultWithWait (
265288 final Class <T > valueClass ,
266289 final String workflowId ,
@@ -269,15 +292,10 @@ public <T> T getSimpleWorkflowResultWithWait(
269292 }
270293
271294 /**
272- * For most cases, a workflow only has one result(one completion state).
273- * Use this API to retrieve the output of the state with waiting for the workflow to complete.
274- * If the workflow is not COMPLETED, throw the {@link feign.FeignException.FeignClientException}.
275- *
276- * @param valueClass required, the type class of the output
277- * @param workflowId required, the workflowId
278- * @param <T> type of the output
279- * @return the output result
295+ * Use {@link #waitForWorkflowCompletion(Class, String)} instead
296+ * It's just a renaming.
280297 */
298+ @ Deprecated
281299 public <T > T getSimpleWorkflowResultWithWait (
282300 final Class <T > valueClass ,
283301 final String workflowId ) {
@@ -922,6 +940,64 @@ public void skipTimer(
922940 unregisteredClient .skipTimer (workflowId , workflowRunId , workflowStateId , stateExecutionNumber , timerCommandIndex );
923941 }
924942
943+ /**
944+ * A long poll API to wait for the completion of the state. This only waits for the first completion.
945+ * Note 1 The stateCompletion to wait for is needed to registered on starting workflow due to limitation in https://github.com/indeedeng/iwf/issues/349
946+ * Note 2 The max polling time is configured as clientOptions as the Feign client timeout(default to 10s)
947+ * If the state is not COMPLETED, throw the {@link ClientSideException} with the sub status of {@link ErrorSubStatus#LONG_POLL_TIME_OUT_SUB_STATUS}
948+ * @param workflowId the workflowId
949+ * @param stateClass the state class.
950+ */
951+ public void waitForStateExecutionCompletion (
952+ final String workflowId ,
953+ final Class <? extends WorkflowState > stateClass ) {
954+ this .waitForStateExecutionCompletion (Void .class , workflowId , stateClass , 1 );
955+ }
956+
957+ /**
958+ * A long poll API to wait for the completion of the state. This only waits for the first completion.
959+ * Note 1 The stateCompletion to wait for is needed to registered on starting workflow due to limitation in https://github.com/indeedeng/iwf/issues/349
960+ * Note 2 The max polling time is configured as clientOptions as the Feign client timeout(default to 10s)
961+ * If the state is not COMPLETED, throw the {@link ClientSideException} with the sub status of {@link ErrorSubStatus#LONG_POLL_TIME_OUT_SUB_STATUS}
962+ * @param valueClass the result of the state completion. Could be Void if not interested
963+ * @param workflowId the workflowId
964+ * @param stateClass the state class.
965+ * @return the result of the state completion
966+ * @param <T> the result type of the state completion
967+ */
968+ public <T > T waitForStateExecutionCompletion (
969+ final Class <T > valueClass ,
970+ final String workflowId ,
971+ final Class <? extends WorkflowState > stateClass ) {
972+ return this .waitForStateExecutionCompletion (valueClass , workflowId , stateClass , 1 );
973+ }
974+
975+ /**
976+ * A long poll API to wait for the completion of the state. This only waits for the first completion.
977+ * Note 1 The stateCompletion and stateExecutionNumber to wait for must be registered on starting workflow due to limitation in https://github.com/indeedeng/iwf/issues/349
978+ * Note 2 The max polling time is configured as clientOptions as the Feign client timeout(default to 10s)
979+ * If the state is not COMPLETED, throw the {@link ClientSideException} with the sub status of {@link ErrorSubStatus#LONG_POLL_TIME_OUT_SUB_STATUS}
980+ * @param valueClass the result of the state completion. Could be Void if not interested
981+ * @param workflowId the workflowId
982+ * @param stateClass the state class
983+ * @param stateExecutionNumber the state execution number. E.g. if it's 2, it means the 2nd execution of the state
984+ * @return the result of the state completion
985+ * @param <T> the result type of the state completion
986+ */
987+ public <T > T waitForStateExecutionCompletion (
988+ final Class <T > valueClass ,
989+ final String workflowId ,
990+ final Class <? extends WorkflowState > stateClass ,
991+ final int stateExecutionNumber ) {
992+ final String stateExecutionId = WorkflowState .getStateExecutionId (stateClass , stateExecutionNumber );
993+ return unregisteredClient .waitForStateExecutionCompletion (valueClass , workflowId , stateExecutionId );
994+ }
995+
996+
997+ /**
998+ * This method is deprecated, use the method with stateClass instead for strongly typing experience
999+ */
1000+ @ Deprecated
9251001 public <T > T waitForStateExecutionCompletion (
9261002 final Class <T > valueClass ,
9271003 final String workflowId ,
0 commit comments