|
6 | 6 | from iwf.command_results import CommandResults
|
7 | 7 | from iwf.communication import Communication
|
8 | 8 | from iwf.iwf_api.models import RetryPolicy
|
| 9 | +from iwf.iwf_api.models.wait_until_api_failure_policy import WaitUntilApiFailurePolicy |
9 | 10 | from iwf.persistence import Persistence
|
10 | 11 | from iwf.state_decision import StateDecision
|
11 | 12 | from iwf.state_schema import StateSchema
|
|
16 | 17 | from iwf.workflow_state_options import WorkflowStateOptions
|
17 | 18 |
|
18 | 19 |
|
19 |
| -class FailState(WorkflowState[None]): |
| 20 | +class FailWaitUntilState(WorkflowState[None]): |
| 21 | + def wait_until( |
| 22 | + self, |
| 23 | + ctx: WorkflowContext, |
| 24 | + input: T, |
| 25 | + persistence: Persistence, |
| 26 | + communication: Communication, |
| 27 | + ): |
| 28 | + raise RuntimeError("failed wait_until") |
| 29 | + |
| 30 | + def execute( |
| 31 | + self, |
| 32 | + ctx: WorkflowContext, |
| 33 | + input: T, |
| 34 | + command_results: CommandResults, |
| 35 | + persistence: Persistence, |
| 36 | + communication: Communication, |
| 37 | + ): |
| 38 | + return StateDecision.single_next_state(FailExecuteState) |
| 39 | + |
| 40 | + def get_state_options(self) -> WorkflowStateOptions: |
| 41 | + return WorkflowStateOptions( |
| 42 | + execute_api_retry_policy=RetryPolicy(maximum_attempts=1), |
| 43 | + wait_until_api_retry_policy=RetryPolicy(maximum_attempts=1), |
| 44 | + proceed_to_execute_when_wait_until_retry_exhausted=WaitUntilApiFailurePolicy.PROCEED_ON_FAILURE, |
| 45 | + ) |
| 46 | + |
| 47 | + |
| 48 | +class FailExecuteState(WorkflowState[None]): |
20 | 49 | def execute(
|
21 | 50 | self,
|
22 | 51 | ctx: WorkflowContext,
|
@@ -48,17 +77,20 @@ def execute(
|
48 | 77 |
|
49 | 78 | class RecoveryWorkflow(ObjectWorkflow):
|
50 | 79 | def get_workflow_states(self) -> StateSchema:
|
51 |
| - return StateSchema.with_starting_state(FailState(), RecoveryState()) |
52 |
| - |
53 |
| - |
54 |
| -wf = RecoveryWorkflow() |
55 |
| -registry.add_workflow(wf) |
56 |
| -client = Client(registry) |
| 80 | + return StateSchema.with_starting_state( |
| 81 | + FailWaitUntilState(), FailExecuteState(), RecoveryState() |
| 82 | + ) |
57 | 83 |
|
58 | 84 |
|
59 | 85 | class Test(unittest.TestCase):
|
| 86 | + @classmethod |
| 87 | + def setUpClass(cls): |
| 88 | + wf = RecoveryWorkflow() |
| 89 | + registry.add_workflow(wf) |
| 90 | + cls.client = Client(registry) |
| 91 | + |
60 | 92 | def test_workflow_recovery(self):
|
61 | 93 | wf_id = f"{inspect.currentframe().f_code.co_name}-{time.time_ns()}"
|
62 |
| - client.start_workflow(RecoveryWorkflow, wf_id, 10) |
63 |
| - result = client.get_simple_workflow_result_with_wait(wf_id, str) |
| 94 | + self.client.start_workflow(RecoveryWorkflow, wf_id, 10) |
| 95 | + result = self.client.wait_for_workflow_completion(wf_id, str) |
64 | 96 | assert result == "done"
|
0 commit comments