Skip to content
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

feat(py-stepfunctions): add step-mapping to example #215

Merged
merged 9 commits into from
Jan 16, 2020
Binary file modified python/stepfunctions/statemachine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 40 additions & 13 deletions python/stepfunctions/stepfunctions/stepfunctions_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,77 @@ class JobPollerStack(core.Stack):
def __init__(self, app: core.App, id: str, **kwargs) -> None:
super().__init__(app, id, **kwargs)

submit_job_activity = sfn.Activity(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't align with our syntactic python conventions. Please revert to xx = xx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted to xx = xx.

submit_job_activity=sfn.Activity(
self, "SubmitJob"
)
check_job_activity = sfn.Activity(
check_job_activity=sfn.Activity(
self, "CheckJob"
)
do_mapping_activity1=sfn.Activity(
self, "MapJOb1"
)
do_mapping_activity2=sfn.Activity(
self, "MapJOb2"
)

submit_job = sfn.Task(
submit_job=sfn.Task(
self, "Submit Job",
task=sfn_tasks.InvokeActivity(submit_job_activity),
result_path="$.guid",
)
wait_x = sfn.Wait(

task1=sfn.Task(
self, "Task 1 in Mapping",
task=sfn_tasks.InvokeActivity(do_mapping_activity1),
result_path="$.guid",
)

task2=sfn.Task(
self, "Task 2 in Mapping",
task=sfn_tasks.InvokeActivity(do_mapping_activity2),
result_path="$.guid",
)

wait_x=sfn.Wait(
self, "Wait X Seconds",
time=sfn.WaitTime.seconds_path('$.wait_time'),
)
get_status = sfn.Task(
get_status=sfn.Task(
self, "Get Job Status",
task=sfn_tasks.InvokeActivity(check_job_activity),
input_path="$.guid",
result_path="$.status",
)
is_complete = sfn.Choice(
is_complete=sfn.Choice(
self, "Job Complete?"
)
job_failed = sfn.Fail(
job_failed=sfn.Fail(
self, "Job Failed",
cause="AWS Batch Job Failed",
error="DescribeJob returned FAILED"
)
final_status = sfn.Task(
final_status=sfn.Task(
self, "Get Final Job Status",
task=sfn_tasks.InvokeActivity(check_job_activity),
input_path="$.guid",
)

definition = submit_job\
.next(wait_x)\
.next(get_status)\
definition_map=task1.next(task2)

process_map=sfn.Map(
self, "Process_map",
max_concurrency=10
).iterator(definition_map)

definition=submit_job \
.next(process_map) \
.next(wait_x) \
.next(get_status) \
.next(is_complete
.when(sfn.Condition.string_equals(
"$.status", "FAILED"), job_failed)
"$.status", "FAILED"), job_failed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing. Revert to original indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed Indentation

.when(sfn.Condition.string_equals(
"$.status", "SUCCEEDED"), final_status)
"$.status", "SUCCEEDED"), final_status)
.otherwise(wait_x))

sfn.StateMachine(
Expand Down