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

Support timeout in BatchOperator #45619

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions providers/src/airflow/providers/amazon/aws/operators/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class BatchOperator(BaseOperator):
If it is an array job, only the logs of the first task will be printed.
:param awslogs_fetch_interval: The interval with which cloudwatch logs are to be fetched, 30 sec.
:param poll_interval: (Deferrable mode only) Time in seconds to wait between polling.
:param timeout: timeout configuration for SubmitJob.

.. note::
Any custom waiters must return a waiter for these calls:
Expand Down Expand Up @@ -184,6 +185,7 @@ def __init__(
poll_interval: int = 30,
awslogs_enabled: bool = False,
awslogs_fetch_interval: timedelta = timedelta(seconds=30),
timeout: dict | None = None,
**kwargs,
) -> None:
BaseOperator.__init__(self, **kwargs)
Expand All @@ -208,6 +210,7 @@ def __init__(
self.poll_interval = poll_interval
self.awslogs_enabled = awslogs_enabled
self.awslogs_fetch_interval = awslogs_fetch_interval
self.timeout = timeout
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be mistakenly confused with Airflow task timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would batch_job_timeout be better?

Copy link
Contributor

@eladkal eladkal Jan 13, 2025

Choose a reason for hiding this comment

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

I think keeping same/similar name as boto3 interface is simpler

Copy link
Contributor

Choose a reason for hiding this comment

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

Please lets not use timeout.
You can use the same name as boto3 or choose something else but not names that can cause confusion with BaseOperator parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

boto3_timeout would make sense I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm open to boto3_timeout, batch_job_timeout, job_timeout etc, whatever is acceptable.


# params for hook
self.max_retries = max_retries
Expand Down Expand Up @@ -313,6 +316,7 @@ def submit_job(self, context: Context):
"retryStrategy": self.retry_strategy,
"shareIdentifier": self.share_identifier,
"schedulingPriorityOverride": self.scheduling_priority_override,
"timeout": self.timeout,
}

try:
Expand Down
7 changes: 7 additions & 0 deletions providers/tests/amazon/aws/operators/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def setup_method(self, _, get_client_type_mock):
aws_conn_id="airflow_test",
region_name="eu-west-1",
tags={},
timeout={"attemptDurationSeconds": 3600},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vincbeck Should I be adding timeout={"attemptDurationSeconds": 3600}, to assert_called_once_with calls?

https://github.com/apache/airflow/actions/runs/12751882848/job/35600073343?pr=45619#step:11:3020

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please

)
self.client_mock = self.get_client_type_mock.return_value
# We're mocking all actual AWS calls and don't need a connection. This
Expand Down Expand Up @@ -109,6 +110,7 @@ def test_init(self):
assert self.batch.hook.client == self.client_mock
assert self.batch.tags == {}
assert self.batch.wait_for_completion is True
assert self.batch.timeout == {"attemptDurationSeconds": 3600}

self.get_client_type_mock.assert_called_once_with(region_name="eu-west-1")

Expand Down Expand Up @@ -141,6 +143,7 @@ def test_init_defaults(self):
assert issubclass(type(batch_job.hook.client), botocore.client.BaseClient)
assert batch_job.tags == {}
assert batch_job.wait_for_completion is True
assert batch_job.timeout is None

def test_template_fields_overrides(self):
assert self.batch.template_fields == (
Expand Down Expand Up @@ -181,6 +184,7 @@ def test_execute_without_failures(self, check_mock, wait_mock, job_description_m
parameters={},
retryStrategy={"attempts": 1},
tags={},
timeout={"attemptDurationSeconds": 3600},
)

assert self.batch.job_id == JOB_ID
Expand All @@ -205,6 +209,7 @@ def test_execute_with_failures(self):
parameters={},
retryStrategy={"attempts": 1},
tags={},
timeout={"attemptDurationSeconds": 3600},
)

@mock.patch.object(BatchClientHook, "get_job_description")
Expand Down Expand Up @@ -261,6 +266,7 @@ def test_execute_with_ecs_overrides(self, check_mock, wait_mock, job_description
parameters={},
retryStrategy={"attempts": 1},
tags={},
timeout={"attemptDurationSeconds": 3600},
)

@mock.patch.object(BatchClientHook, "get_job_description")
Expand Down Expand Up @@ -359,6 +365,7 @@ def test_execute_with_eks_overrides(self, check_mock, wait_mock, job_description
parameters={},
retryStrategy={"attempts": 1},
tags={},
timeout={"attemptDurationSeconds": 3600},
)

@mock.patch.object(BatchClientHook, "check_job_success")
Expand Down