From f04adb720234e6c6746d780f0609e891654d4c27 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 18 Aug 2022 13:41:28 +0200 Subject: [PATCH] Bug fix - automatically queued watch checks weren't always being processed sequentially --- changedetectionio/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 07558d8a..594747ef 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -1385,13 +1385,18 @@ def ticker_thread_check_time_launch_checks(): seconds_since_last_recheck = now - watch['last_checked'] if seconds_since_last_recheck >= (threshold + watch.jitter_seconds) and seconds_since_last_recheck >= recheck_time_minimum_seconds: if not uuid in running_uuids and uuid not in [q_uuid for p,q_uuid in update_q.queue]: - print("> Queued watch UUID {} last checked at {} queued at {:0.2f} jitter {:0.2f}s, {:0.2f}s since last checked".format(uuid, - watch['last_checked'], - now, - watch.jitter_seconds, - now - watch['last_checked'])) + # Use Epoch time as priority, so we get a "sorted" PriorityQueue, but we can still push a priority 1 into it. + priority = int(time.time()) + print( + "> Queued watch UUID {} last checked at {} queued at {:0.2f} priority {} jitter {:0.2f}s, {:0.2f}s since last checked".format( + uuid, + watch['last_checked'], + now, + priority, + watch.jitter_seconds, + now - watch['last_checked'])) # Into the queue with you - update_q.put((5, uuid)) + update_q.put((priority, uuid)) # Reset for next time watch.jitter_seconds = 0