-
Notifications
You must be signed in to change notification settings - Fork 90
fix: Retrier and Catcher passed to constructor for Task, Parallel and Map states are not added to the state's Retriers and Catchers #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
79c66c3
Add retry to Retriers when passed to constructor and add catch to Cat…
ca-nguyen 7f0ceff
Added integ tests
ca-nguyen 30e8da9
Use fstring in raised exception
ca-nguyen 0582e91
Merge branch 'main' into fix-retry-in-task-constructor
ca-nguyen abf2656
Write unit test for each state and update docstrings to use ASL retri…
ca-nguyen f3a0cc1
Merge branch 'fix-retry-in-task-constructor' of https://github.com/ca…
ca-nguyen cd1fc9e
Removed integ test for retry and catch in constructor and updated exi…
ca-nguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,18 +422,38 @@ def test_task_state_machine_creation(sfn_client, sfn_role_arn, training_job_para | |
|
||
def test_catch_state_machine_creation(sfn_client, sfn_role_arn, training_job_parameters): | ||
catch_state_name = "TaskWithCatchState" | ||
custom_error = "CustomError" | ||
task_failed_error = "States.TaskFailed" | ||
all_fail_error = "States.ALL" | ||
custom_error_state_name = "Custom Error End" | ||
task_failed_state_name = "Task Failed End" | ||
all_error_state_name = "Catch All End" | ||
timeout_error = "States.Timeout" | ||
task_failed_state_name = "Catch Task Failed End" | ||
timeout_state_name = "Catch Timeout End" | ||
catch_state_result = "Catch Result" | ||
task_resource = f"arn:{get_aws_partition()}:states:::sagemaker:createTrainingJob.sync" | ||
|
||
# change the parameters to cause task state to fail | ||
# Provide invalid TrainingImage to cause States.TaskFailed error | ||
training_job_parameters["AlgorithmSpecification"]["TrainingImage"] = "not_an_image" | ||
|
||
task = steps.Task( | ||
catch_state_name, | ||
parameters=training_job_parameters, | ||
resource=task_resource, | ||
catch=steps.Catch( | ||
error_equals=[timeout_error], | ||
next_step=steps.Pass(timeout_state_name, result=catch_state_result) | ||
) | ||
) | ||
task.add_catch( | ||
steps.Catch( | ||
error_equals=[task_failed_error], | ||
next_step=steps.Pass(task_failed_state_name, result=catch_state_result) | ||
) | ||
) | ||
|
||
workflow = Workflow( | ||
unique_name_from_base('Test_Catch_Workflow'), | ||
definition=task, | ||
role=sfn_role_arn | ||
) | ||
|
||
asl_state_machine_definition = { | ||
ca-nguyen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"StartAt": catch_state_name, | ||
"States": { | ||
|
@@ -445,80 +465,61 @@ def test_catch_state_machine_creation(sfn_client, sfn_role_arn, training_job_par | |
"Catch": [ | ||
{ | ||
"ErrorEquals": [ | ||
all_fail_error | ||
timeout_error | ||
], | ||
"Next": all_error_state_name | ||
"Next": timeout_state_name | ||
}, | ||
{ | ||
"ErrorEquals": [ | ||
task_failed_error | ||
], | ||
"Next": task_failed_state_name | ||
} | ||
] | ||
}, | ||
all_error_state_name: { | ||
task_failed_state_name: { | ||
"Type": "Pass", | ||
"Result": catch_state_result, | ||
"End": True | ||
} | ||
}, | ||
timeout_state_name: { | ||
"Type": "Pass", | ||
"Result": catch_state_result, | ||
"End": True | ||
}, | ||
} | ||
} | ||
task = steps.Task( | ||
catch_state_name, | ||
parameters=training_job_parameters, | ||
resource=task_resource | ||
) | ||
task.add_catch( | ||
steps.Catch( | ||
error_equals=[all_fail_error], | ||
next_step=steps.Pass(all_error_state_name, result=catch_state_result) | ||
) | ||
) | ||
|
||
workflow = Workflow( | ||
unique_name_from_base('Test_Catch_Workflow'), | ||
definition=task, | ||
role=sfn_role_arn | ||
) | ||
|
||
workflow_test_suite(sfn_client, workflow, asl_state_machine_definition, catch_state_result) | ||
|
||
|
||
def test_retry_state_machine_creation(sfn_client, sfn_role_arn, training_job_parameters): | ||
retry_state_name = "RetryStateName" | ||
all_fail_error = "Starts.ALL" | ||
task_failed_error = "States.TaskFailed" | ||
timeout_error = "States.Timeout" | ||
interval_seconds = 1 | ||
max_attempts = 2 | ||
backoff_rate = 2 | ||
task_resource = f"arn:{get_aws_partition()}:states:::sagemaker:createTrainingJob.sync" | ||
|
||
# change the parameters to cause task state to fail | ||
# Provide invalid TrainingImage to cause States.TaskFailed error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you, it's a lot less mysterious what we're trying to do now |
||
training_job_parameters["AlgorithmSpecification"]["TrainingImage"] = "not_an_image" | ||
|
||
asl_state_machine_definition = { | ||
"StartAt": retry_state_name, | ||
"States": { | ||
retry_state_name: { | ||
"Resource": task_resource, | ||
"Parameters": training_job_parameters, | ||
"Type": "Task", | ||
"End": True, | ||
"Retry": [ | ||
{ | ||
"ErrorEquals": [all_fail_error], | ||
"IntervalSeconds": interval_seconds, | ||
"MaxAttempts": max_attempts, | ||
"BackoffRate": backoff_rate | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
task = steps.Task( | ||
retry_state_name, | ||
parameters=training_job_parameters, | ||
resource=task_resource | ||
resource=task_resource, | ||
retry=steps.Retry( | ||
error_equals=[timeout_error], | ||
interval_seconds=interval_seconds, | ||
max_attempts=max_attempts, | ||
backoff_rate=backoff_rate | ||
) | ||
) | ||
|
||
task.add_retry( | ||
steps.Retry( | ||
error_equals=[all_fail_error], | ||
error_equals=[task_failed_error], | ||
interval_seconds=interval_seconds, | ||
max_attempts=max_attempts, | ||
backoff_rate=backoff_rate | ||
|
@@ -531,4 +532,30 @@ def test_retry_state_machine_creation(sfn_client, sfn_role_arn, training_job_par | |
role=sfn_role_arn | ||
) | ||
|
||
workflow_test_suite(sfn_client, workflow, asl_state_machine_definition, None) | ||
asl_state_machine_definition = { | ||
"StartAt": retry_state_name, | ||
"States": { | ||
retry_state_name: { | ||
"Resource": task_resource, | ||
"Parameters": training_job_parameters, | ||
"Type": "Task", | ||
"End": True, | ||
"Retry": [ | ||
{ | ||
"ErrorEquals": [timeout_error], | ||
"IntervalSeconds": interval_seconds, | ||
"MaxAttempts": max_attempts, | ||
"BackoffRate": backoff_rate | ||
}, | ||
{ | ||
"ErrorEquals": [task_failed_error], | ||
"IntervalSeconds": interval_seconds, | ||
"MaxAttempts": max_attempts, | ||
"BackoffRate": backoff_rate | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
workflow_test_suite(sfn_client, workflow, asl_state_machine_definition, None) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.