Skip to content

Commit 9d4cb58

Browse files
committed
feature: add ability to use waitForTaskToken for ECS tasks
1 parent aafdb76 commit 9d4cb58

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Diff for: src/stepfunctions/steps/compute.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ class EcsRunTaskStep(Task):
166166
Creates a Task State to run Amazon ECS or Fargate Tasks. See `Manage Amazon ECS or Fargate Tasks with Step Functions <https://docs.aws.amazon.com/step-functions/latest/dg/connect-ecs.html>`_ for more details.
167167
"""
168168

169-
def __init__(self, state_id, wait_for_completion=True, **kwargs):
169+
def __init__(self, state_id, wait_for_completion=True, wait_for_callback=False, **kwargs):
170170
"""
171171
Args:
172172
state_id (str): State name whose length **must be** less than or equal to 128 unicode characters. State names **must be** unique within the scope of the whole state machine.
173173
wait_for_completion(bool, optional): Boolean value set to `True` if the Task state should wait for the ecs job to complete before proceeding to the next step in the workflow. Set to `False` if the Task state should submit the ecs job and proceed to the next step. (default: True)
174+
wait_for_callback(bool, optional): Boolean value set to `True` if the Task state should wait for callback to resume the operation. (default: False)
174175
timeout_seconds (int, optional): Positive integer specifying timeout for the state in seconds. If the state runs longer than the specified timeout, then the interpreter fails the state with a `States.Timeout` Error Name. (default: 60)
175176
timeout_seconds_path (str, optional): Path specifying the state's timeout value in seconds from the state input. When resolved, the path must select a field whose value is a positive integer.
176177
heartbeat_seconds (int, optional): Positive integer specifying heartbeat timeout for the state in seconds. This value should be lower than the one specified for `timeout_seconds`. If more time than the specified heartbeat elapses between heartbeats from the task, then the interpreter fails the state with a `States.Timeout` Error Name.
@@ -181,7 +182,18 @@ def __init__(self, state_id, wait_for_completion=True, **kwargs):
181182
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
182183
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
183184
"""
184-
if wait_for_completion:
185+
if wait_for_completion and wait_for_callback:
186+
raise ValueError("Only one of wait_for_completion and wait_for_callback can be true")
187+
188+
if wait_for_callback:
189+
"""
190+
Example resource arn: arn:aws:states:::ecs:runTask.waitForTaskToken
191+
"""
192+
193+
kwargs[Field.Resource.value] = get_service_integration_arn(ECS_SERVICE_NAME,
194+
EcsApi.RunTask,
195+
IntegrationPattern.WaitForTaskToken)
196+
elif wait_for_completion:
185197
"""
186198
Example resource arn: arn:aws:states:::ecs:runTask.sync
187199
"""

Diff for: tests/unit/test_compute_steps.py

+13
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ def test_ecs_run_task_step_creation():
109109
'End': True
110110
}
111111

112+
step = EcsRunTaskStep('Ecs Job', wait_for_callback=True)
113+
114+
assert step.to_dict() == {
115+
'Type': 'Task',
116+
'Resource': 'arn:aws:states:::ecs:runTask.waitForTaskToken',
117+
'End': True
118+
}
119+
112120
step = EcsRunTaskStep('Ecs Job', parameters={
113121
'TaskDefinition': 'Task'
114122
})
@@ -121,3 +129,8 @@ def test_ecs_run_task_step_creation():
121129
},
122130
'End': True
123131
}
132+
133+
with pytest.raises(ValueError):
134+
step = EcsRunTaskStep('Ecs Job',
135+
wait_for_completion=True,
136+
wait_for_callback=True)

0 commit comments

Comments
 (0)