Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:47:31

0001 """The comp snapshot as JSON (docs/COMP_SNAPSHOT.md): the computing
0002 centre room's live record. ``?refresh=1`` rebuilds before answering."""
0003 import logging
0004 
0005 from django.http import JsonResponse
0006 
0007 from monitor_app.comp_snapshot import get_snapshot
0008 
0009 logger = logging.getLogger(__name__)
0010 
0011 # The room is drawn in the etaverse world, which fetches the record from
0012 # the browser.
0013 ALLOWED_ORIGIN = 'https://etaverse.com'
0014 
0015 
0016 def comp_snapshot_json(request):
0017     refresh = str(request.GET.get('refresh', '')).lower() in ('1', 'true', 'yes')
0018     try:
0019         data = get_snapshot(refresh=refresh)
0020         response = JsonResponse(data)
0021     except Exception as exc:  # noqa: BLE001
0022         logger.exception("comp snapshot failed")
0023         response = JsonResponse({'error': f'{type(exc).__name__}: {exc}'}, status=503)
0024     response['Access-Control-Allow-Origin'] = ALLOWED_ORIGIN
0025     response['Cache-Control'] = 'no-cache'
0026     return response