stale[bot] closed pull request #2513: [AIRFLOW-XXX] Allow setting of 
keepalives_idle to enable PostgresHook to work with Amazon Redshift
URL: https://github.com/apache/incubator-airflow/pull/2513
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index 3c85942bf1..b82cdb4d37 100644
--- a/README.md
+++ b/README.md
@@ -87,7 +87,7 @@ Currently **officially** using Airflow:
 1. [allegro.pl](http://allegro.tech/) [[@kretes](https://github.com/kretes)]
 1. [AltX](https://www.getaltx.com/about) 
[[@pedromduarte](https://github.com/pedromduarte)]
 1. [Apigee](https://apigee.com) [[@btallman](https://github.com/btallman)]
-1. [ARGO Labs](http://www.argolabs.org) [[California Data 
Collaborative](https://github.com/California-Data-Collaborative)] 
+1. [ARGO Labs](http://www.argolabs.org) [[California Data 
Collaborative](https://github.com/California-Data-Collaborative)]
 1. [Astronomer](http://www.astronomer.io) 
[[@schnie](https://github.com/schnie)]
 1. [Auth0](https://auth0.com) [[@sicarul](https://github.com/sicarul)]
 1. [BandwidthX](http://www.bandwidthx.com) 
[[@dineshdsharma](https://github.com/dineshdsharma)]
@@ -135,7 +135,7 @@ Currently **officially** using Airflow:
 1. [liligo](http://liligo.com/) [[@tromika](https://github.com/tromika)]
 1. [LingoChamp](http://www.liulishuo.com/) 
[[@haitaoyao](https://github.com/haitaoyao)]
 1. [Lucid](http://luc.id) [[@jbrownlucid](https://github.com/jbrownlucid) & 
[@kkourtchikov](https://github.com/kkourtchikov)]
-1. [Lumos Labs](https://www.lumosity.com/) 
[[@rfroetscher](https://github.com/rfroetscher/) & 
[@zzztimbo](https://github.com/zzztimbo/)]
+1. [Lumos Labs](https://www.lumosity.com/)
 1. 
[Lyft](https://www.lyft.com/)[[@SaurabhBajaj](https://github.com/SaurabhBajaj)]
 1. [Madrone](http://madroneco.com/) 
[[@mbreining](https://github.com/mbreining) & 
[@scotthb](https://github.com/scotthb)]
 1. [Markovian](https://markovian.com/) [[@al-xv](https://github.com/al-xv), 
[@skogsbaeck](https://github.com/skogsbaeck), 
[@waltherg](https://github.com/waltherg)]
diff --git a/airflow/hooks/postgres_hook.py b/airflow/hooks/postgres_hook.py
index c8de85bb0a..0ce732e805 100644
--- a/airflow/hooks/postgres_hook.py
+++ b/airflow/hooks/postgres_hook.py
@@ -23,6 +23,8 @@ class PostgresHook(DbApiHook):
     Interact with Postgres.
     You can specify ssl parameters in the extra field of your connection
     as ``{"sslmode": "require", "sslcert": "/path/to/cert.pem", etc}``.
+
+    Note: For Redshift, set the keepalives_idle to less than 300 seconds!
     """
     conn_name_attr = 'postgres_conn_id'
     default_conn_name = 'postgres_default'
@@ -31,6 +33,7 @@ class PostgresHook(DbApiHook):
     def __init__(self, *args, **kwargs):
         super(PostgresHook, self).__init__(*args, **kwargs)
         self.schema = kwargs.pop("schema", None)
+        self.keepalives_idle = kwargs.pop("keepalives_idle", 0)
 
     def get_conn(self):
         conn = self.get_connection(self.postgres_conn_id)
@@ -39,7 +42,8 @@ def get_conn(self):
             user=conn.login,
             password=conn.password,
             dbname=self.schema or conn.schema,
-            port=conn.port)
+            port=conn.port,
+            keepalives_idle=self.keepalives_idle)
         # check for ssl parameters in conn.extra
         for arg_name, arg_val in conn.extra_dejson.items():
             if arg_name in ['sslmode', 'sslcert', 'sslkey', 'sslrootcert', 
'sslcrl', 'application_name']:
@@ -52,8 +56,8 @@ def _serialize_cell(cell, conn):
         """
         Postgresql will adapt all arguments to the execute() method internally,
         hence we return cell without any conversion.
-        
-        See http://initd.org/psycopg/docs/advanced.html#adapting-new-types for 
+
+        See http://initd.org/psycopg/docs/advanced.html#adapting-new-types for
         more information.
 
         :param cell: The cell to insert into the table


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to