Coverage for src / local_deep_research / web / auth / queue_middleware_v2.py: 78%

19 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-01-11 00:51 +0000

1""" 

2Queue middleware v2 - notifies queue processor of user activity. 

3""" 

4 

5from flask import g, session 

6from loguru import logger 

7 

8from .middleware_optimizer import should_skip_queue_checks 

9 

10 

11def notify_queue_processor(): 

12 """ 

13 Notify the queue processor that this user is active. 

14 Called as a before_request handler. 

15 """ 

16 # Skip for GET requests and other operations that don't need queue processing 

17 if should_skip_queue_checks(): 

18 return 

19 

20 username = session.get("username") 

21 session_id = session.get("session_id") 

22 

23 if username and session_id: 

24 # Only notify if user has database connection (authenticated) 

25 if hasattr(g, "db_session") and g.db_session: 25 ↛ exitline 25 didn't return from function 'notify_queue_processor' because the condition on line 25 was always true

26 try: 

27 from ..queue.processor_v2 import queue_processor 

28 

29 # Notify the processor to check this user's queue 

30 queue_processor.notify_user_activity(username, session_id) 

31 

32 # Also trigger immediate processing if needed 

33 queued_count = queue_processor.process_user_request( 

34 username, session_id 

35 ) 

36 if queued_count > 0: 36 ↛ 37line 36 didn't jump to line 37 because the condition on line 36 was never true

37 logger.debug( 

38 f"User {username} has {queued_count} queued items, " 

39 f"processor notified" 

40 ) 

41 

42 except Exception: 

43 # Don't let queue errors break the request 

44 logger.exception("Error notifying queue processor") 

45 pass