Back to home page

EIC code displayed by LXR

 
 

    


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

0001 """Worker starts behind the production dashboard's slots/hour link."""
0002 from django.shortcuts import render
0003 from rest_framework.authentication import SessionAuthentication, TokenAuthentication
0004 from rest_framework.decorators import api_view, authentication_classes, permission_classes
0005 from rest_framework.permissions import IsAuthenticated
0006 from rest_framework.response import Response
0007 
0008 from monitor_app.models import PandaQueue
0009 from monitor_app.short_names import short_name
0010 from monitor_app.worker_admission import product, startup_evidence
0011 from swf_epicprod.regulation import RETIRED_QUEUES
0012 
0013 
0014 @api_view(['GET'])
0015 @authentication_classes([TokenAuthentication, SessionAuthentication])
0016 @permission_classes([IsAuthenticated])
0017 def osg_image_demand(request):
0018     from monitor_app.worker_admission import osg_image_demand as collect
0019     try:
0020         limits = {key: int(request.GET[key]) for key in ('memory_mb', 'cores')}
0021         if any(value < 1 or value > 2**31 - 1 for value in limits.values()):
0022             raise ValueError('invalid limits')
0023     except (KeyError, ValueError):
0024         return Response({'detail': 'positive memory_mb and cores are required'}, status=400)
0025     return Response(collect(**limits))
0026 
0027 
0028 def worker_admission(request):
0029     selected = request.GET.get('site') or 'BNL_OSG_PanDA_1'
0030     queues = [name.strip() for name in selected.split(',')
0031               if name.strip() and name.strip() not in RETIRED_QUEUES]
0032     queues = queues or ['BNL_OSG_PanDA_1']
0033     try:
0034         hours = int(request.GET.get('hours', 1))
0035     except (TypeError, ValueError):
0036         hours = 1
0037     if hours not in (1, 3, 6, 12):
0038         hours = 1
0039     result = product(queues, hours, refresh=request.GET.get('refresh') == '1')
0040     data = result.get('value') or None
0041     return render(request, 'monitor_app/worker_admission.html', {
0042         'queue_label': ', '.join(short_name(name) for name in queues),
0043         'selected_queue': ','.join(queues),
0044         'queue_choices': list(PandaQueue.objects.exclude(queue_name__in=RETIRED_QUEUES)
0045                               .order_by('queue_name').values_list('queue_name', flat=True)),
0046         'hours': hours, 'hour_options': (1, 3, 6, 12), 'data': data,
0047         'evidence': startup_evidence(queues), 'failure': (data or {}).get('error'),
0048     })