Skip to content

Commit 006035d

Browse files
author
Denis Zhuk
committed
Configure backoff
1 parent cbe1ce9 commit 006035d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ A dbt profile can be configured to run against Presto using the following config
1919
| schema | Specify the schema to build models into | Required | `dbt_drew` |
2020
| region_name | Specify in which AWS region it should connect | Required | `eu-west-1` |
2121
| threads | How many threads dbt should use | Optional(default=`1`) | `8` |
22+
| max_retry_number | Number for retries for exponential backoff | Optional(default=`5`) | `8` |
23+
| max_retry_delay | Maximum delay for exponential backoff in seconds | Optional(default=`100`) | `8` |
2224

2325

2426
**Example profiles.yml entry:**

dbt/adapters/athena/connections.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pyathena.async_cursor import AsyncCursor
1818
from pyathena.error import OperationalError
1919
from pyathena.model import AthenaQueryExecution
20+
from pyathena.util import RetryConfig
2021

2122

2223
@dataclass
@@ -26,6 +27,8 @@ class AthenaCredentials(Credentials):
2627
s3_staging_dir: str
2728
region_name: str
2829
threads: int = 1
30+
max_retry_number: int = 5
31+
max_retry_delay: int = 100
2932

3033
_ALIASES = {
3134
'catalog': 'database'
@@ -36,7 +39,12 @@ def type(self) -> str:
3639
return 'athena'
3740

3841
def _connection_keys(self) -> Tuple[str]:
39-
return ('s3_staging_dir', 'database', 'schema', 'region_name')
42+
return (
43+
's3_staging_dir',
44+
'database',
45+
'schema',
46+
'region_name'
47+
)
4048

4149

4250
class CursorWrapper(object):
@@ -168,7 +176,8 @@ def open(cls, connection):
168176
s3_staging_dir=credentials.s3_staging_dir,
169177
region_name=credentials.region_name,
170178
schema_name=credentials.database,
171-
cursor_class=AsyncCursor
179+
cursor_class=AsyncCursor,
180+
retry_config=RetryConfig(attempt=credentials.max_retry_number, max_delay=credentials.max_retry_delay)
172181
)
173182
connection.state = 'open'
174183
connection.handle = ConnectionWrapper(conn, credentials.threads)

0 commit comments

Comments
 (0)