Visitar URL original
fix: fix timeout issue for long-running queries by ssalmani-ledger · Pull Request #15 · dacker-team/pyred · GitHub
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
14 changes: 10 additions & 4 deletions pyred/RedDBStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ def __init__(self, instance_name, client_id):

def connection(self):
connection_kwargs = self.credentials()
keepalive_kwargs = {
"keepalives": 1,
"keepalives_idle": 30,
"keepalives_interval": 5,
"keepalives_count": 5,
}
try:
con = psycopg2.connect(**connection_kwargs, cursor_factory=RealDictCursor)
con = psycopg2.connect(**connection_kwargs, **keepalive_kwargs, cursor_factory=RealDictCursor)
except psycopg2.OperationalError:
time.sleep(2)
if self.ssh_tunnel:
self.ssh_tunnel.close()
self.create_tunnel()
con = psycopg2.connect(**connection_kwargs, cursor_factory=RealDictCursor)
con = psycopg2.connect(**connection_kwargs, **keepalive_kwargs, cursor_factory=RealDictCursor)
return con

def _execute_query_custom(self, query):
Expand Down Expand Up @@ -201,7 +207,7 @@ def clean(self, selecting_id, schema_prefix, table):
print('trying to clean table %s.%s using %s' % (schema_prefix, table, selecting_id))
cleaning_query = """
DELETE FROM %(schema_name)s.%(table_name)s WHERE %(id)s IN (SELECT distinct %(id)s FROM %(schema_name)s.%(table_name)s_temp);
INSERT INTO %(schema_name)s.%(table_name)s
INSERT INTO %(schema_name)s.%(table_name)s
SELECT * FROM %(schema_name)s.%(table_name)s_temp;
DELETE FROM %(schema_name)s.%(table_name)s_temp;
""" % {"table_name": table,
Expand All @@ -228,7 +234,7 @@ def get_data_type(self, table_name, schema_name):
information_schema.columns
WHERE
table_name = '%s' and table_schema = '%s'
union
union
select col_name as column_name , col_type as data_type
from pg_get_late_binding_view_cols() cols(view_schema name, view_name name, col_name name, col_type varchar, col_num int)
WHERE
Expand Down