Skip to content

Commit

Permalink
Upgrade waitForCompletionState to wait for all executions (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Jul 26, 2024
1 parent f0f81c6 commit bddeb54
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion iwf-idl
1 change: 1 addition & 0 deletions src/main/java/io/iworkflow/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public String startWorkflow(
unregisterWorkflowOptions.workflowRetryPolicy(options.getWorkflowRetryPolicy());
unregisterWorkflowOptions.workflowConfigOverride(options.getWorkflowConfigOverride());
unregisterWorkflowOptions.waitForCompletionStateExecutionIds(options.getWaitForCompletionStateExecutionIds());
unregisterWorkflowOptions.waitForCompletionStateIds(options.getWaitForCompletionStateIds());

final Map<String, SearchAttributeValueType> saTypes = registry.getSearchAttributeKeyToTypeMap(wfType);
final List<SearchAttribute> convertedSAs = convertToSearchAttributeList(saTypes, options.getInitialSearchAttribute());
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/iworkflow/core/UnregisteredClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public String startWorkflow(
request.workflowStartOptions(startOptions);

request.waitForCompletionStateExecutionIds(options.getWaitForCompletionStateExecutionIds());
request.waitForCompletionStateIds(options.getWaitForCompletionStateIds());
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public abstract class UnregisteredWorkflowOptions {
public abstract Optional<Boolean> getUsingMemoForDataAttributes();

public abstract List<String> getWaitForCompletionStateExecutionIds();

public abstract List<String> getWaitForCompletionStateIds();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class WorkflowOptionBuilderExtension {
private ImmutableWorkflowOptions.Builder builder = ImmutableWorkflowOptions.builder();

/**
* Add a state to wait for completion. This only waiting for the first completion of the state
* Add a state to wait for completion. This only waiting for all the completion of the state executions
* NOTE: this will not be needed/required once server implements <a href="https://github.com/indeedeng/iwf/issues/349">this</a>
* @param state The state to wait for completion.
* @return The builder.
Expand All @@ -21,22 +21,22 @@ public WorkflowOptionBuilderExtension waitForCompletionState(Class<? extends Wor
}

/**
* Add states to wait for completion. This only waiting for the first completion of the state
* Add states to wait for completion. This only waiting for all the completion of the state executions
* NOTE: this will not be needed/required once server implements <a href="https://github.com/indeedeng/iwf/issues/349">this</a>
* @param states The states to wait for completion.
* @return The builder.
*/
@SafeVarargs
public final WorkflowOptionBuilderExtension waitForCompletionStates(Class<? extends WorkflowState>... states) {
Arrays.stream(states).forEach(
state -> builder.addWaitForCompletionStateExecutionIds(
WorkflowState.getStateExecutionId(state,1)
state -> builder.addWaitForCompletionStateIds(
WorkflowState.getDefaultStateId(state)
));
return this;
}

/**
* Add a state to wait for completion. This can wait for any times completion of the state
* Add a state to wait for completion. This can wait for a certain completion of the state execution
* @param state The state to wait for completion.
* @param number The number of the state completion to wait for. E.g. when it's 2, it's waiting for the second completion of the state.
* @return The builder.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/iworkflow/core/WorkflowOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class WorkflowOptions {

public abstract Optional<WorkflowConfig> getWorkflowConfigOverride();

public abstract List<String> getWaitForCompletionStateIds();
public abstract List<String> getWaitForCompletionStateExecutionIds();

public static WorkflowOptionBuilderExtension extendedBuilder() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/io/iworkflow/core/WorkflowState.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ StateDecision execute(
* @return the StateId of the state
*/
default String getStateId() {
return this.getClass().getSimpleName();
return getDefaultStateId(this.getClass());
}

/**
Expand Down Expand Up @@ -116,6 +116,10 @@ static boolean shouldSkipWaitUntil(final WorkflowState state) {
static String getStateExecutionId(Class<? extends WorkflowState> state, int number) {
return String.format("%s-%d", state.getSimpleName(), number);
}

static String getDefaultStateId(Class<? extends WorkflowState> state) {
return state.getSimpleName();
}
}


0 comments on commit bddeb54

Please sign in to comment.