File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,9 @@ def route_signal_to_replica_model(
65
65
66
66
is_meta_supported = model_cls .CQRS_META
67
67
try :
68
+ if db_is_needed :
69
+ _apply_query_timeouts (model_cls )
70
+
68
71
with transaction .atomic (savepoint = False ) if db_is_needed else ExitStack ():
69
72
if signal_type == SignalType .DELETE :
70
73
if is_meta_supported :
@@ -97,3 +100,24 @@ def route_signal_to_replica_model(
97
100
model_cls .CQRS_ID ,
98
101
),
99
102
)
103
+
104
+
105
+ def _apply_query_timeouts (model_cls ): # pragma: no cover
106
+ query_timeout = int (settings .CQRS ['replica' ].get ('CQRS_QUERY_TIMEOUT' , 0 ))
107
+ if query_timeout <= 0 :
108
+ return
109
+
110
+ model_db = model_cls ._default_manager .db
111
+ conn = transaction .get_connection (using = model_db )
112
+ conn_vendor = getattr (conn , 'vendor' , '' )
113
+
114
+ if conn_vendor not in {'postgresql' , 'mysql' }:
115
+ return
116
+
117
+ if conn_vendor == 'postgresql' :
118
+ statement = 'SET statement_timeout TO %s'
119
+ else :
120
+ statement = 'SET SESSION MAX_EXECUTION_TIME=%s'
121
+
122
+ with conn .cursor () as cursor :
123
+ cursor .execute (statement , params = (query_timeout ,))
You can’t perform that action at this time.
0 commit comments