MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / fetch_channel_stats

Function fetch_channel_stats

apps/proxy/tasks.py:16–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14
15@shared_task
16def fetch_channel_stats():
17 redis_client = RedisClient.get_client()
18
19 try:
20 # Basic info for all channels
21 channel_pattern = "live:channel:*:metadata"
22 all_channels = []
23
24 # Extract channel IDs from keys
25 cursor = 0
26 while True:
27 cursor, keys = redis_client.scan(cursor, match=channel_pattern)
28 for key in keys:
29 channel_id_match = re.search(r"live:channel:(.*):metadata", key)
30 if channel_id_match:
31 ch_id = channel_id_match.group(1)
32 channel_info = ChannelStatus.get_basic_channel_info(ch_id)
33 if channel_info:
34 all_channels.append(channel_info)
35
36 if cursor == 0:
37 break
38
39 except Exception as e:
40 logger.error(f"Error in channel_status: {e}", exc_info=True)
41 return
42 # return JsonResponse({'error': str(e)}, status=500)
43
44 send_websocket_update(
45 "updates",
46 "update",
47 {
48 "success": True,
49 "type": "channel_stats",
50 "stats": json.dumps({'channels': all_channels, 'count': len(all_channels)})
51 },
52 collect_garbage=True
53 )
54
55 # Explicitly clean up large data structures
56 all_channels = None
57 gc.collect()
58
59

Callers

nothing calls this directly

Calls 5

send_websocket_updateFunction · 0.90
get_clientMethod · 0.80
scanMethod · 0.80
searchMethod · 0.80

Tested by

no test coverage detected