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

Function send_websocket_notification

core/utils.py:908–953  ·  view source on GitHub ↗

Send a system notification to all connected WebSocket clients. Args: notification: A SystemNotification model instance or dict with notification data Example: from core.models import SystemNotification notification = SystemNotification.create_version_notificati

(notification)

Source from the content-addressed store, hash-verified

906
907
908def send_websocket_notification(notification):
909 """
910 Send a system notification to all connected WebSocket clients.
911
912 Args:
913 notification: A SystemNotification model instance or dict with notification data
914
915 Example:
916 from core.models import SystemNotification
917 notification = SystemNotification.create_version_notification('0.19.0', 'https://...')
918 send_websocket_notification(notification)
919 """
920 try:
921 channel_layer = get_channel_layer()
922
923 # Convert model instance to dict if needed
924 if hasattr(notification, 'id'):
925 notification_data = {
926 'id': notification.id,
927 'notification_key': notification.notification_key,
928 'notification_type': notification.notification_type,
929 'priority': notification.priority,
930 'title': notification.title,
931 'message': notification.message,
932 'action_data': notification.action_data,
933 'is_active': notification.is_active,
934 'admin_only': notification.admin_only,
935 'created_at': notification.created_at.isoformat() if notification.created_at else None,
936 }
937 else:
938 notification_data = notification
939
940 _send_async(
941 channel_layer,
942 'updates',
943 {
944 'type': 'update',
945 'data': {
946 'type': 'system_notification',
947 'notification': notification_data,
948 }
949 }
950 )
951 logger.debug(f"Sent WebSocket notification: {notification_data.get('title', 'Unknown')}")
952 except Exception as e:
953 logger.error(f"Failed to send WebSocket notification: {e}")
954
955
956def get_host_and_port(request):

Calls 2

_send_asyncFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected