StepFunctions: Ensure that all operations respect the FAILURE env var (#6204)

This commit is contained in:
Bert Blommers 2023-04-12 09:26:28 +00:00 committed by GitHub
parent dda6e573dd
commit c44f0b7395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 1 deletions

View File

@ -31,13 +31,40 @@ stepfunctions
- [X] delete_state_machine - [X] delete_state_machine
- [ ] describe_activity - [ ] describe_activity
- [X] describe_execution - [X] describe_execution
The status of every execution is set to 'RUNNING' by default.
Set the following environment variable if you want to get a FAILED status back:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
- [ ] describe_map_run - [ ] describe_map_run
- [X] describe_state_machine - [X] describe_state_machine
- [ ] describe_state_machine_for_execution - [ ] describe_state_machine_for_execution
- [ ] get_activity_task - [ ] get_activity_task
- [X] get_execution_history - [X] get_execution_history
A static list of successful events is returned by default.
Set the following environment variable if you want to get a static list of events for a failed execution:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
- [ ] list_activities - [ ] list_activities
- [X] list_executions - [X] list_executions
The status of every execution is set to 'RUNNING' by default.
Set the following environment variable if you want to get a FAILED status back:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
- [ ] list_map_runs - [ ] list_map_runs
- [X] list_state_machines - [X] list_state_machines
- [X] list_tags_for_resource - [X] list_tags_for_resource

View File

@ -230,7 +230,11 @@ class Execution:
self.start_date = iso_8601_datetime_with_milliseconds(datetime.now()) self.start_date = iso_8601_datetime_with_milliseconds(datetime.now())
self.state_machine_arn = state_machine_arn self.state_machine_arn = state_machine_arn
self.execution_input = execution_input self.execution_input = execution_input
self.status = "RUNNING" self.status = (
"RUNNING"
if settings.get_sf_execution_history_type() == "SUCCESS"
else "FAILED"
)
self.stop_date = None self.stop_date = None
def get_execution_history(self, roleArn): def get_execution_history(self, roleArn):
@ -510,6 +514,14 @@ class StepFunctionBackend(BaseBackend):
@paginate(pagination_model=PAGINATION_MODEL) @paginate(pagination_model=PAGINATION_MODEL)
def list_executions(self, state_machine_arn, status_filter=None): def list_executions(self, state_machine_arn, status_filter=None):
"""
The status of every execution is set to 'RUNNING' by default.
Set the following environment variable if you want to get a FAILED status back:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
"""
executions = self.describe_state_machine(state_machine_arn).executions executions = self.describe_state_machine(state_machine_arn).executions
if status_filter: if status_filter:
@ -519,6 +531,14 @@ class StepFunctionBackend(BaseBackend):
return executions return executions
def describe_execution(self, execution_arn): def describe_execution(self, execution_arn):
"""
The status of every execution is set to 'RUNNING' by default.
Set the following environment variable if you want to get a FAILED status back:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
"""
self._validate_execution_arn(execution_arn) self._validate_execution_arn(execution_arn)
state_machine = self._get_state_machine_for_execution(execution_arn) state_machine = self._get_state_machine_for_execution(execution_arn)
exctn = next( exctn = next(
@ -532,6 +552,14 @@ class StepFunctionBackend(BaseBackend):
return exctn return exctn
def get_execution_history(self, execution_arn): def get_execution_history(self, execution_arn):
"""
A static list of successful events is returned by default.
Set the following environment variable if you want to get a static list of events for a failed execution:
.. sourcecode:: bash
SF_EXECUTION_HISTORY_TYPE=FAILURE
"""
self._validate_execution_arn(execution_arn) self._validate_execution_arn(execution_arn)
state_machine = self._get_state_machine_for_execution(execution_arn) state_machine = self._get_state_machine_for_execution(execution_arn)
execution = next( execution = next(

View File

@ -950,6 +950,12 @@ def test_state_machine_get_execution_history_contains_expected_failure_events_wh
execution_history["events"].should.have.length_of(3) execution_history["events"].should.have.length_of(3)
execution_history["events"].should.equal(expected_events) execution_history["events"].should.equal(expected_events)
exc = client.describe_execution(executionArn=execution["executionArn"])
assert exc["status"] == "FAILED"
exc = client.list_executions(stateMachineArn=sm["stateMachineArn"])["executions"][0]
assert exc["status"] == "FAILED"
def _get_default_role(): def _get_default_role():
return "arn:aws:iam::" + ACCOUNT_ID + ":role/unknown_sf_role" return "arn:aws:iam::" + ACCOUNT_ID + ":role/unknown_sf_role"