mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2026-01-02 01:27:03 -05:00
feat: Implement initial schema and add various API, service, and management command enhancements across the application.
This commit is contained in:
@@ -4,6 +4,7 @@ Server-Sent Events (SSE) endpoint for real-time moderation dashboard updates.
|
||||
This module provides a streaming HTTP response that broadcasts submission status
|
||||
changes to connected moderators in real-time.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import queue
|
||||
@@ -103,6 +104,7 @@ class ModerationSSEView(APIView):
|
||||
|
||||
Sends a heartbeat every 30 seconds to keep the connection alive.
|
||||
"""
|
||||
|
||||
def event_stream() -> Generator[str]:
|
||||
client_queue = sse_broadcaster.subscribe()
|
||||
|
||||
@@ -124,13 +126,10 @@ class ModerationSSEView(APIView):
|
||||
finally:
|
||||
sse_broadcaster.unsubscribe(client_queue)
|
||||
|
||||
response = StreamingHttpResponse(
|
||||
event_stream(),
|
||||
content_type='text/event-stream'
|
||||
)
|
||||
response['Cache-Control'] = 'no-cache'
|
||||
response['X-Accel-Buffering'] = 'no' # Disable nginx buffering
|
||||
response['Connection'] = 'keep-alive'
|
||||
response = StreamingHttpResponse(event_stream(), content_type="text/event-stream")
|
||||
response["Cache-Control"] = "no-cache"
|
||||
response["X-Accel-Buffering"] = "no" # Disable nginx buffering
|
||||
response["Connection"] = "keep-alive"
|
||||
|
||||
return response
|
||||
|
||||
@@ -168,15 +167,17 @@ class ModerationSSETestView(APIView):
|
||||
|
||||
sse_broadcaster.broadcast(test_payload)
|
||||
|
||||
return JsonResponse({
|
||||
"status": "ok",
|
||||
"message": f"Test event broadcast to {len(sse_broadcaster._subscribers)} clients",
|
||||
"payload": test_payload,
|
||||
})
|
||||
return JsonResponse(
|
||||
{
|
||||
"status": "ok",
|
||||
"message": f"Test event broadcast to {len(sse_broadcaster._subscribers)} clients",
|
||||
"payload": test_payload,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
'ModerationSSEView',
|
||||
'ModerationSSETestView',
|
||||
'sse_broadcaster',
|
||||
"ModerationSSEView",
|
||||
"ModerationSSETestView",
|
||||
"sse_broadcaster",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user