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

Add retryer to SFTP hook connection #13065

Merged
merged 1 commit into from
Feb 3, 2021
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
8 changes: 8 additions & 0 deletions airflow/providers/sftp/hooks/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from typing import Dict, List, Optional, Tuple

import pysftp
import tenacity
from paramiko import SSHException

from airflow.providers.ssh.hooks.ssh import SSHHook

Expand Down Expand Up @@ -109,6 +111,12 @@ def __init__(self, ftp_conn_id: str = 'sftp_default', *args, **kwargs) -> None:
)
self.key_file = extra_options.get('private_key')

@tenacity.retry(
stop=tenacity.stop_after_delay(10),
wait=tenacity.wait_exponential(multiplier=1, max=10),
retry=tenacity.retry_if_exception_type(SSHException),
reraise=True,
)
def get_conn(self) -> pysftp.Connection:
"""Returns an SFTP connection object"""
if self.conn is None:
Expand Down