Skip to content

Commit cdf43ea

Browse files
awelsh93Chris Fei
authored and
Chris Fei
committed
Raise ValueError if timeout < 1 in druid hook
1 parent 7704c88 commit cdf43ea

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

airflow/hooks/druid_hook.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class DruidHook(BaseHook):
3737
which accepts index jobs
3838
:type druid_ingest_conn_id: string
3939
:param timeout: The interval between polling
40-
the Druid job for the status of the ingestion job
40+
the Druid job for the status of the ingestion job.
41+
Must be greater than or equal to 1
4142
:type timeout: int
4243
:param max_ingestion_time: The maximum ingestion time before assuming the job failed
4344
:type max_ingestion_time: int
@@ -53,6 +54,9 @@ def __init__(
5354
self.max_ingestion_time = max_ingestion_time
5455
self.header = {'content-type': 'application/json'}
5556

57+
if self.timeout < 1:
58+
raise ValueError("Druid timeout should be equal or greater than 1")
59+
5660
def get_conn_url(self):
5761
conn = self.get_connection(self.druid_ingest_conn_id)
5862
host = conn.host

tests/hooks/test_druid_hook.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_submit_unknown_response(self, m):
9898

9999
@requests_mock.mock()
100100
def test_submit_timeout(self, m):
101-
self.db_hook.timeout = 0
101+
self.db_hook.timeout = 1
102102
self.db_hook.max_ingestion_time = 5
103103
task_post = m.post(
104104
'http://druid-overlord:8081/druid/indexer/v1/task',
@@ -131,7 +131,7 @@ def test_get_conn_url(self, mock_get_connection):
131131
get_conn_value.port = '1'
132132
get_conn_value.extra_dejson = {'endpoint': 'ingest'}
133133
mock_get_connection.return_value = get_conn_value
134-
hook = DruidHook(timeout=0, max_ingestion_time=5)
134+
hook = DruidHook(timeout=1, max_ingestion_time=5)
135135
self.assertEquals(hook.get_conn_url(), 'https://test_host:1/ingest')
136136

137137

0 commit comments

Comments
 (0)