From db10e90801d29364e2c92abf771b082aaf4068bd Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Fri, 11 Jul 2025 15:51:19 -0500 Subject: [PATCH] Enhance rehash_streams task to send WebSocket notifications for blocked rehash attempts.. --- core/tasks.py | 21 ++++++++++++++++++--- frontend/src/WebSocket.jsx | 8 ++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/core/tasks.py b/core/tasks.py index 0b0c4705..e8b36162 100644 --- a/core/tasks.py +++ b/core/tasks.py @@ -311,7 +311,7 @@ def fetch_channel_stats(): return @shared_task -def rehash_streams(): +def rehash_streams(keys): """ Regenerate stream hashes for all streams based on current hash key configuration. This task checks for and blocks M3U refresh tasks to prevent conflicts. @@ -327,7 +327,7 @@ def rehash_streams(): # Check if any M3U refresh tasks are currently running blocked_accounts = [] for account_id in m3u_account_ids: - if not acquire_task_lock('refresh_single_m3u_account', account_id, timeout=0): + if not acquire_task_lock('refresh_single_m3u_account', account_id): blocked_accounts.append(account_id) if blocked_accounts: @@ -337,6 +337,21 @@ def rehash_streams(): release_task_lock('refresh_single_m3u_account', account_id) logger.warning(f"Rehash blocked: M3U refresh tasks running for accounts: {blocked_accounts}") + + # Send WebSocket notification to inform user + send_websocket_update( + 'updates', + 'update', + { + "success": False, + "type": "stream_rehash", + "action": "blocked", + "blocked_accounts": len(blocked_accounts), + "total_accounts": len(m3u_account_ids), + "message": f"Stream rehash blocked: M3U refresh tasks are currently running for {len(blocked_accounts)} accounts. Please try again later." + } + ) + return f"Rehash blocked: M3U refresh tasks running for {len(blocked_accounts)} accounts" acquired_locks = m3u_account_ids.copy() @@ -351,7 +366,7 @@ def rehash_streams(): hash_keys = {} total_records = queryset.count() - logger.info(f"Starting rehash of {total_records} streams") + logger.info(f"Starting rehash of {total_records} streams with keys: {keys}") # Send initial WebSocket update send_websocket_update( diff --git a/frontend/src/WebSocket.jsx b/frontend/src/WebSocket.jsx index 314f82e9..538ffda3 100644 --- a/frontend/src/WebSocket.jsx +++ b/frontend/src/WebSocket.jsx @@ -406,6 +406,14 @@ export const WebsocketProvider = ({ children }) => { withCloseButton: true, // Allow manual close loading: false, // Remove loading indicator }); + } else if (parsedEvent.data.action === 'blocked') { + // Handle blocked rehash attempt + notifications.show({ + title: 'Stream Rehash Blocked', + message: parsedEvent.data.message, + color: 'orange.5', + autoClose: 8000, + }); } break;