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.
37 changes: 32 additions & 5 deletions python/stepfunctions/stepfunctions/stepfunctions_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,31 @@ def __init__(self, app: core.App, id: str, **kwargs) -> None:
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(
self, "Submit Job",
task=sfn_tasks.InvokeActivity(submit_job_activity),
result_path="$.guid",
)

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'),
Expand All @@ -45,14 +64,22 @@ def __init__(self, app: core.App, id: str, **kwargs) -> None:
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)
.when(sfn.Condition.string_equals(
"$.status", "SUCCEEDED"), final_status)
"$.status", "SUCCEEDED"), final_status)
.otherwise(wait_x))

sfn.StateMachine(
Expand Down