From 3fb1a96d7e6b1160503b36ea428b72efae62ba9f Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 24 Nov 2025 18:27:55 +0100 Subject: [PATCH] Signal handling for realtime info --- changedetectionio/async_update_worker.py | 5 +++++ .../watchlist/templates/watch-overview.html | 2 +- changedetectionio/content_fetchers/base.py | 1 + changedetectionio/processors/__init__.py | 2 ++ changedetectionio/realtime/events.py | 2 +- changedetectionio/realtime/socket_server.py | 20 +++++++++++++++++++ changedetectionio/static/js/realtime.js | 5 +++++ changedetectionio/templates/base.html | 2 +- 8 files changed, 36 insertions(+), 3 deletions(-) diff --git a/changedetectionio/async_update_worker.py b/changedetectionio/async_update_worker.py index f796c9f6f..4f7f4249d 100644 --- a/changedetectionio/async_update_worker.py +++ b/changedetectionio/async_update_worker.py @@ -1,3 +1,5 @@ +from blinker import signal + from .processors.exceptions import ProcessorException import changedetectionio.content_fetchers.exceptions as content_fetchers_exceptions from changedetectionio.processors.text_json_diff.processor import FilterNotFoundInResponse @@ -97,6 +99,9 @@ async def async_update_worker(worker_id, q, notification_q, app, datastore): update_handler = processor_module.perform_site_check(datastore=datastore, watch_uuid=uuid) + update_signal = signal('watch_small_status_comment') + update_signal.send(watch_uuid=uuid, status="Fetching page..") + # All fetchers are now async, so call directly await update_handler.call_browser() diff --git a/changedetectionio/blueprint/watchlist/templates/watch-overview.html b/changedetectionio/blueprint/watchlist/templates/watch-overview.html index 3e08e69b4..54d5ed2cc 100644 --- a/changedetectionio/blueprint/watchlist/templates/watch-overview.html +++ b/changedetectionio/blueprint/watchlist/templates/watch-overview.html @@ -217,7 +217,7 @@ document.addEventListener('DOMContentLoaded', function() { {#last_checked becomes fetch-start-time#} {{watch|format_last_checked_time|safe}} diff --git a/changedetectionio/content_fetchers/base.py b/changedetectionio/content_fetchers/base.py index 247a99651..351424fe0 100644 --- a/changedetectionio/content_fetchers/base.py +++ b/changedetectionio/content_fetchers/base.py @@ -116,6 +116,7 @@ class Fetcher(): request_method=None, timeout=None, url=None, + watch_uuid=None, ): # Should set self.error, self.status_code and self.content pass diff --git a/changedetectionio/processors/__init__.py b/changedetectionio/processors/__init__.py index 4aa877617..e74f2359e 100644 --- a/changedetectionio/processors/__init__.py +++ b/changedetectionio/processors/__init__.py @@ -23,6 +23,7 @@ class difference_detection_processor(): def __init__(self, *args, datastore, watch_uuid, **kwargs): super().__init__(*args, **kwargs) self.datastore = datastore + self.watch_uuid = watch_uuid self.watch = deepcopy(self.datastore.data['watching'].get(watch_uuid)) # Generic fetcher that should be extended (requests, playwright etc) self.fetcher = Fetcher() @@ -160,6 +161,7 @@ class difference_detection_processor(): request_method=request_method, timeout=timeout, url=url, + watch_uuid=self.watch_uuid, ) #@todo .quit here could go on close object, so we can run JS if change-detected diff --git a/changedetectionio/realtime/events.py b/changedetectionio/realtime/events.py index a68ea99cf..7c0397dd0 100644 --- a/changedetectionio/realtime/events.py +++ b/changedetectionio/realtime/events.py @@ -5,7 +5,7 @@ from blinker import signal def register_watch_operation_handlers(socketio, datastore): """Register Socket.IO event handlers for watch operations""" - + @socketio.on('watch_operation') def handle_watch_operation(data): """Handle watch operations like pause, mute, recheck via Socket.IO""" diff --git a/changedetectionio/realtime/socket_server.py b/changedetectionio/realtime/socket_server.py index 4e3b390f6..107d1e6a7 100644 --- a/changedetectionio/realtime/socket_server.py +++ b/changedetectionio/realtime/socket_server.py @@ -32,11 +32,31 @@ class SignalHandler: watch_favicon_bumped_signal = signal('watch_favicon_bump') watch_favicon_bumped_signal.connect(self.handle_watch_bumped_favicon_signal, weak=False) + watch_small_status_comment_signal = signal('watch_small_status_comment') + watch_small_status_comment_signal.connect(self.handle_watch_small_status_update, weak=False) + # Connect to the notification_event signal notification_event_signal = signal('notification_event') notification_event_signal.connect(self.handle_notification_event, weak=False) logger.info("SignalHandler: Connected to notification_event signal") + + def handle_watch_small_status_update(self, *args, **kwargs): + """Small simple status update, for example 'Connecting...'""" + watch_uuid = kwargs.get('watch_uuid') + status = kwargs.get('status') + + if watch_uuid and status: + logger.debug(f"Socket.IO: Received watch small status update '{status}' for UUID {watch_uuid}") + # Emit the status update to all connected clients + self.socketio_instance.emit("watch_small_status_comment", { + "uuid": watch_uuid, + "status": status, + "event_timestamp": time.time() + }) + + + def handle_signal(self, *args, **kwargs): logger.trace(f"SignalHandler: Signal received with {len(args)} args and {len(kwargs)} kwargs") # Safely extract the watch UUID from kwargs diff --git a/changedetectionio/static/js/realtime.js b/changedetectionio/static/js/realtime.js index cd00e43a1..167a31f17 100644 --- a/changedetectionio/static/js/realtime.js +++ b/changedetectionio/static/js/realtime.js @@ -101,6 +101,11 @@ $(document).ready(function () { } }); + socket.on('watch_small_status_comment', function (data) { + console.log(`Socket.IO: Operation watch_small_status_comment'${data.uuid}' status ${data.status}`); + $('tr[data-watch-uuid="' + data.uuid + '"] td.last-checked .status-text').html(" ").text(data.status); + }); + socket.on('notification_event', function (data) { console.log(`Stub handler for notification_event ${data.watch_uuid}`) }); diff --git a/changedetectionio/templates/base.html b/changedetectionio/templates/base.html index dd56ed279..499af02bc 100644 --- a/changedetectionio/templates/base.html +++ b/changedetectionio/templates/base.html @@ -241,7 +241,7 @@ - +