From 81fecde3b56f59bf55ec231754247c695a6a8497 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Sat, 26 Apr 2025 08:29:18 -0500 Subject: [PATCH] Add stream name to channel status. --- apps/proxy/ts_proxy/channel_status.py | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/apps/proxy/ts_proxy/channel_status.py b/apps/proxy/ts_proxy/channel_status.py index d4e33f02..fe5b1f3b 100644 --- a/apps/proxy/ts_proxy/channel_status.py +++ b/apps/proxy/ts_proxy/channel_status.py @@ -6,6 +6,7 @@ from .redis_keys import RedisKeys from .constants import TS_PACKET_SIZE, ChannelMetadataField from redis.exceptions import ConnectionError, TimeoutError from .utils import get_logger +from django.db import DatabaseError # Add import for error handling logger = get_logger() @@ -45,6 +46,25 @@ class ChannelStatus: 'buffer_index': int(buffer_index_value.decode('utf-8')) if buffer_index_value else 0, } + # Add stream ID and name information + stream_id_bytes = metadata.get(ChannelMetadataField.STREAM_ID.encode('utf-8')) + if stream_id_bytes: + try: + stream_id = int(stream_id_bytes.decode('utf-8')) + info['stream_id'] = stream_id + + # Look up stream name from database + try: + from apps.channels.models import Stream + stream = Stream.objects.filter(id=stream_id).first() + if stream: + info['stream_name'] = stream.name + logger.debug(f"Added stream name '{stream.name}' for stream ID {stream_id}") + except (ImportError, DatabaseError) as e: + logger.warning(f"Failed to get stream name for ID {stream_id}: {e}") + except ValueError: + logger.warning(f"Invalid stream_id format in Redis: {stream_id_bytes}") + # Add timing information state_changed_field = ChannelMetadataField.STATE_CHANGED_AT.encode('utf-8') if state_changed_field in metadata: @@ -285,6 +305,25 @@ class ChannelStatus: 'uptime': uptime } + # Add stream ID and name information + stream_id_bytes = metadata.get(ChannelMetadataField.STREAM_ID.encode('utf-8')) + if stream_id_bytes: + try: + stream_id = int(stream_id_bytes.decode('utf-8')) + info['stream_id'] = stream_id + + # Look up stream name from database + try: + from apps.channels.models import Stream + stream = Stream.objects.filter(id=stream_id).first() + if stream: + info['stream_name'] = stream.name + logger.debug(f"Added stream name '{stream.name}' for stream ID {stream_id}") + except (ImportError, DatabaseError) as e: + logger.warning(f"Failed to get stream name for ID {stream_id}: {e}") + except ValueError: + logger.warning(f"Invalid stream_id format in Redis: {stream_id_bytes}") + # Add data throughput information to basic info total_bytes_bytes = proxy_server.redis_client.hget(metadata_key, ChannelMetadataField.TOTAL_BYTES.encode('utf-8')) if total_bytes_bytes: