Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from typing import TYPE_CHECKING

import redshift_connector
from redshift_connector import Connection as RedshiftConnection
import tenacity
from redshift_connector import Connection as RedshiftConnection, InterfaceError, OperationalError
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL

Expand Down Expand Up @@ -206,6 +207,14 @@ def get_table_primary_key(self, table: str, schema: str | None = "public") -> li
pk_columns = [row[0] for row in self.get_records(sql, (schema, table))]
return pk_columns or None

@tenacity.retry(
stop=tenacity.stop_after_attempt(5),
wait=tenacity.wait_exponential(max=20),
# OperationalError is thrown when the connection times out
# InterfaceError is thrown when the connection is refused
retry=tenacity.retry_if_exception_type((OperationalError, InterfaceError)),
reraise=True,
)
def get_conn(self) -> RedshiftConnection:
"""Get a ``redshift_connector.Connection`` object."""
conn_params = self._get_conn_params()
Expand Down