mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-11-11 20:17:37 +00:00
Compare commits
1 Commits
3526-refac
...
test-speed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5971e06091 |
@@ -130,40 +130,47 @@ def extract_UUID_from_client(client):
|
|||||||
|
|
||||||
def wait_for_all_checks(client=None):
|
def wait_for_all_checks(client=None):
|
||||||
"""
|
"""
|
||||||
Waits until the queue is empty and workers are idle.
|
Waits until both queues are empty and all workers are idle.
|
||||||
Much faster than the original with adaptive timing.
|
Optimized for Janus queues with minimal delays.
|
||||||
"""
|
"""
|
||||||
from changedetectionio.flask_app import update_q as global_update_q
|
from changedetectionio.flask_app import update_q as global_update_q, notification_q
|
||||||
from changedetectionio import worker_handler
|
from changedetectionio import worker_handler
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
empty_since = None
|
|
||||||
attempt = 0
|
|
||||||
max_attempts = 150 # Still reasonable upper bound
|
|
||||||
|
|
||||||
while attempt < max_attempts:
|
# Much tighter timing with reliable Janus queues
|
||||||
# Start with fast checks, slow down if needed
|
max_attempts = 100 # Reduced from 150
|
||||||
if attempt < 10:
|
|
||||||
time.sleep(0.1) # Very fast initial checks
|
|
||||||
elif attempt < 30:
|
|
||||||
time.sleep(0.3) # Medium speed
|
|
||||||
else:
|
|
||||||
time.sleep(0.8) # Slower for persistent issues
|
|
||||||
|
|
||||||
q_length = global_update_q.qsize()
|
for attempt in range(max_attempts):
|
||||||
|
# Check both queues and worker status
|
||||||
|
update_q_size = global_update_q.qsize()
|
||||||
|
notification_q_size = notification_q.qsize()
|
||||||
running_uuids = worker_handler.get_running_uuids()
|
running_uuids = worker_handler.get_running_uuids()
|
||||||
any_workers_busy = len(running_uuids) > 0
|
any_workers_busy = len(running_uuids) > 0
|
||||||
|
|
||||||
if q_length == 0 and not any_workers_busy:
|
# Both queues empty and no workers processing
|
||||||
if empty_since is None:
|
if update_q_size == 0 and notification_q_size == 0 and not any_workers_busy:
|
||||||
empty_since = time.time()
|
# Small delay to account for items being added to queue during processing
|
||||||
elif time.time() - empty_since >= 0.15: # Shorter wait
|
time.sleep(0.05)
|
||||||
break
|
|
||||||
else:
|
|
||||||
empty_since = None
|
|
||||||
|
|
||||||
attempt += 1
|
# Double-check after brief delay
|
||||||
time.sleep(0.3)
|
update_q_size = global_update_q.qsize()
|
||||||
|
notification_q_size = notification_q.qsize()
|
||||||
|
running_uuids = worker_handler.get_running_uuids()
|
||||||
|
any_workers_busy = len(running_uuids) > 0
|
||||||
|
|
||||||
|
if update_q_size == 0 and notification_q_size == 0 and not any_workers_busy:
|
||||||
|
return # All clear!
|
||||||
|
|
||||||
|
# Adaptive sleep timing - start fast, get slightly slower
|
||||||
|
if attempt < 20:
|
||||||
|
time.sleep(0.05) # Very fast initial checks
|
||||||
|
elif attempt < 50:
|
||||||
|
time.sleep(0.1) # Medium speed
|
||||||
|
else:
|
||||||
|
time.sleep(0.2) # Slower for edge cases
|
||||||
|
|
||||||
|
logger.warning(f"wait_for_all_checks() timed out after {max_attempts} attempts")
|
||||||
|
|
||||||
# Replaced by new_live_server_setup and calling per function scope in conftest.py
|
# Replaced by new_live_server_setup and calling per function scope in conftest.py
|
||||||
def live_server_setup(live_server):
|
def live_server_setup(live_server):
|
||||||
|
|||||||
Reference in New Issue
Block a user