|
1 | 1 | package io.iworkflow.core;
|
2 | 2 |
|
3 | 3 | import io.iworkflow.gen.models.ExecuteApiFailurePolicy;
|
| 4 | +import io.iworkflow.gen.models.WaitUntilApiFailurePolicy; |
4 | 5 | import io.iworkflow.gen.models.WorkflowStateOptions;
|
5 | 6 |
|
6 |
| -// WorkflowStateOptionsExtension provides extension to WorkflowStateOptions |
7 |
| -// to make it easier to build |
| 7 | +/** |
| 8 | + * WorkflowStateOptionsExtension provides extension to WorkflowStateOptions |
| 9 | + * to make it easier to build some fields of the stateOptions. |
| 10 | + * This is also because WorkflowState interface uses WorkflowStateOptions |
| 11 | + * directly instead of using a separate model. |
| 12 | + * See <a href="https://github.com/indeedeng/iwf-java-sdk/issues/200">TODO</a> |
| 13 | + * Example usage in a state implementation: |
| 14 | + * public WorkflowStateOptions getStateOptions() { |
| 15 | + * return new WorkflowStateOptionsExtension() |
| 16 | + * .setProceedAfterRetryExhaustedOnExecute(StateRecoverBasic.class) |
| 17 | + * .executeApiRetryPolicy( |
| 18 | + * new RetryPolicy() |
| 19 | + * .maximumAttempts(10) |
| 20 | + * ); |
| 21 | + * } |
| 22 | + */ |
8 | 23 | public class WorkflowStateOptionsExtension extends WorkflowStateOptions {
|
9 | 24 |
|
| 25 | + /** |
| 26 | + * By default, workflow would fail after execute API retry exhausted. |
| 27 | + * Set the state to proceed to the specified state after the execute API exhausted all retries |
| 28 | + * This is useful for some advanced use cases like SAGA pattern. |
| 29 | + * RetryPolicy is required to be set with maximumAttempts or maximumAttemptsDurationSeconds for execute API. |
| 30 | + * NOTE: The proceeding state will take the same input as the failed state that proceeded from. |
| 31 | + * See more in <a href="https://github.com/indeedeng/iwf/wiki/WorkflowStateOptions">wiki</a> |
| 32 | + * @param proceedingState the state to proceed to |
| 33 | + * @return this |
| 34 | + */ |
| 35 | + public WorkflowStateOptionsExtension setProceedWhenExecuteRetryExhausted( |
| 36 | + final Class<? extends WorkflowState> proceedingState) { |
| 37 | + return this.setProceedOnExecuteFailure(proceedingState); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * By default, workflow would fail after execute API retry exhausted. |
| 42 | + * Set the state to proceed to the specified state after the execute API exhausted all retries |
| 43 | + * This is useful for some advanced use cases like SAGA pattern. |
| 44 | + * RetryPolicy is required to be set with maximumAttempts or maximumAttemptsDurationSeconds for execute API. |
| 45 | + * NOTE: The proceeding state will take the same input as the failed state that proceeded from. |
| 46 | + * See more in <a href="https://github.com/indeedeng/iwf/wiki/WorkflowStateOptions">wiki</a> |
| 47 | + * @param proceedingState the state to proceed to |
| 48 | + * @param stateOptionsOverride the stateOptions for the proceeding state. This is for a rare case that you |
| 49 | + * need to override the stateOptions returned from state instance. |
| 50 | + * @return this |
| 51 | + */ |
| 52 | + public WorkflowStateOptionsExtension setProceedWhenExecuteRetryExhausted( |
| 53 | + final Class<? extends WorkflowState> proceedingState, WorkflowStateOptions stateOptionsOverride) { |
| 54 | + return this.setProceedOnExecuteFailure(proceedingState, stateOptionsOverride); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * By default, workflow would fail after waitUntil API retry exhausted. |
| 59 | + * If set to true, then after waitUntil API exhausted all retries, proceed to the execute API |
| 60 | + * This is useful for some advanced use cases like SAGA pattern. |
| 61 | + * RetryPolicy is required to be set with maximumAttempts or maximumAttemptsDurationSeconds for waitUntil API. |
| 62 | + * NOTE: execute API will use commandResults to check whether the waitUntil has succeeded or not. |
| 63 | + * See more in <a href="https://github.com/indeedeng/iwf/wiki/WorkflowStateOptions">wiki</a> |
| 64 | + * @param proceed true to proceed |
| 65 | + * @return this |
| 66 | + */ |
| 67 | + public WorkflowStateOptionsExtension setProceedWhenWaitUntilRetryExhausted(boolean proceed){ |
| 68 | + if(proceed){ |
| 69 | + this.waitUntilApiFailurePolicy(WaitUntilApiFailurePolicy.PROCEED_ON_FAILURE); |
| 70 | + }else{ |
| 71 | + this.waitUntilApiFailurePolicy(WaitUntilApiFailurePolicy.FAIL_WORKFLOW_ON_FAILURE); |
| 72 | + } |
| 73 | + |
| 74 | + return this; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Use setProceedAfterRetryExhaustedOnExecuteFailure instead. |
| 79 | + * It's a renaming for better clarity. |
| 80 | + */ |
| 81 | + @Deprecated |
10 | 82 | public WorkflowStateOptionsExtension setProceedOnExecuteFailure(final Class<? extends WorkflowState> proceedingState) {
|
11 | 83 | this.executeApiFailurePolicy(ExecuteApiFailurePolicy.PROCEED_TO_CONFIGURED_STATE);
|
12 | 84 | this.executeApiFailureProceedStateId(proceedingState.getSimpleName());
|
13 | 85 | return this;
|
14 | 86 | }
|
15 | 87 |
|
16 |
| - public WorkflowStateOptionsExtension setProceedOnExecuteFailure(final Class<? extends WorkflowState> proceedingState, WorkflowStateOptions stateOptions) { |
| 88 | + /** |
| 89 | + * Use setProceedAfterRetryExhaustedOnExecuteFailure instead |
| 90 | + * It's a renaming for better clarity. |
| 91 | + */ |
| 92 | + @Deprecated |
| 93 | + public WorkflowStateOptionsExtension setProceedOnExecuteFailure(final Class<? extends WorkflowState> proceedingState, WorkflowStateOptions stateOptionsOverride) { |
17 | 94 | this.executeApiFailurePolicy(ExecuteApiFailurePolicy.PROCEED_TO_CONFIGURED_STATE);
|
18 | 95 | this.executeApiFailureProceedStateId(proceedingState.getSimpleName());
|
19 |
| - this.executeApiFailureProceedStateOptions(stateOptions); |
| 96 | + this.executeApiFailureProceedStateOptions(stateOptionsOverride); |
20 | 97 | return this;
|
21 | 98 | }
|
22 | 99 | }
|
0 commit comments