Skip to content

Commit

Permalink
LITE-27792 Initial support for MySQL replica CQRS_QUERY_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
maxipavlovic committed Jun 19, 2023
1 parent df213df commit 416dc8a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions dj_cqrs/controller/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ def _apply_query_timeouts(model_cls): # pragma: no cover

model_db = model_cls._default_manager.db
conn = transaction.get_connection(using=model_db)
if getattr(conn, 'vendor', 'postgresql'):
with conn.cursor() as cursor:
cursor.execute('SET statement_timeout TO %s', params=(query_timeout,))
conn_vendor = getattr(conn, 'vendor', '')

if conn_vendor not in {'postgresql', 'mysql'}:
return

if conn_vendor == 'postgresql':
statement = 'SET statement_timeout TO %s'
else:
statement = 'SET SESSION MAX_EXECUTION_TIME=%s'

with conn.cursor() as cursor:
cursor.execute(statement, params=(query_timeout,))

0 comments on commit 416dc8a

Please sign in to comment.