1313
1414logger = logging .getLogger (__name__ )
1515
16- # HITL connectors registry (initialized at module level, similar to Redis pattern)
17- hitl_connectors = {}
18-
1916
2017class QueueResultStatus (Enum ):
2118 SUCCESS = "success"
@@ -24,6 +21,9 @@ class QueueResultStatus(Enum):
2421
2522
2623class QueueUtils :
24+ # HITL connectors registry (lazy-loaded to avoid circular imports)
25+ _hitl_connectors = {}
26+
2727 @staticmethod
2828 def get_queue_inst (connector_settings : dict [str , Any ] = {}) -> UnstractQueue :
2929 """Get queue connector instance based on configuration.
@@ -71,7 +71,10 @@ def get_hitl_queue_inst(
7171 """
7272 # For Redis backend, use default connector
7373 if backend == "redis" :
74- return QueueUtils .get_queue_inst (connector_settings )
74+ # Strip HITL flag to force default (non-HITL) connector path
75+ non_hitl_settings = dict (connector_settings )
76+ non_hitl_settings .pop ("use_hitl_backend" , None )
77+ return QueueUtils .get_queue_inst (non_hitl_settings )
7578
7679 # For PostgreSQL and Hybrid backends, try dynamic imports
7780 try :
@@ -107,9 +110,9 @@ def get_hitl_queue_inst(
107110 detail = f"Failed to initialize HITL queue backend '{ backend } ': { str (e )} "
108111 )
109112
110- @staticmethod
111- def _import_hitl_connector (connector_name : str ):
112- """Get HITL connector class from registry (follows Redis pattern with lazy loading ).
113+ @classmethod
114+ def _import_hitl_connector (cls , connector_name : str ):
115+ """Get HITL connector class from registry (lazy-loaded to avoid circular imports ).
113116
114117 Args:
115118 connector_name: Name of the connector class to get
@@ -120,35 +123,33 @@ def _import_hitl_connector(connector_name: str):
120123 Raises:
121124 ImportError: When the connector is not available
122125 """
123- global hitl_connectors
124-
125126 # Lazy initialization on first access (avoids circular imports)
126- if not hitl_connectors :
127+ if not cls . _hitl_connectors :
127128 try :
128129 from pluggable_apps .manual_review_v2 .connectors import (
129130 HybridQueue ,
130131 PostgreSQLQueue ,
131132 )
132133
133- hitl_connectors = {
134+ cls . _hitl_connectors = {
134135 "PostgreSQLQueue" : PostgreSQLQueue ,
135136 "HybridQueue" : HybridQueue ,
136137 }
137138 except ImportError as e :
138139 logger .debug (f"HITL connectors not available: { e } " )
139140
140- if not hitl_connectors :
141+ if not cls . _hitl_connectors :
141142 raise ImportError (
142143 "HITL connectors not available. Make sure 'pluggable_apps.manual_review_v2' is installed."
143144 )
144145
145- if connector_name not in hitl_connectors :
146- available_connectors = list (hitl_connectors .keys ())
146+ if connector_name not in cls . _hitl_connectors :
147+ available_connectors = list (cls . _hitl_connectors .keys ())
147148 raise ImportError (
148149 f"Unknown HITL connector: { connector_name } . Available: { available_connectors } "
149150 )
150151
151- return hitl_connectors [connector_name ]
152+ return cls . _hitl_connectors [connector_name ]
152153
153154 @staticmethod
154155 def calculate_remaining_ttl (enqueued_at : float , ttl_seconds : int ) -> int | None :
0 commit comments