Skip to content

Commit

Permalink
Allow super user to bypass ratelimit
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Mar 29, 2024
1 parent 28f58b3 commit 3098b06
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,24 @@ def create(self, request, format="json"):
"""
runs the job.
"""
if (
ExportRun.objects.filter(
created_at__gt=timezone.now() - timedelta(minutes=1), user=request.user
).count()
>= 1
):
return Response(
{"status": "RATE_LIMITED"}, status=status.HTTP_400_BAD_REQUEST
)
if not request.user.is_superuser:
if (
ExportRun.objects.filter(
created_at__gt=timezone.now() - timedelta(minutes=1),
user=request.user,
).count()
>= 1
):
return Response(
{"status": "RATE_LIMITED"}, status=status.HTTP_400_BAD_REQUEST
)

job_uid = request.query_params.get("job_uid", None)
if Job.objects.get(uid=job_uid).last_run_status == "SUBMITTED":
return Response(
{"status": "PREVIOUS_RUN_IN_QUEUE"}, status=status.HTTP_400_BAD_REQUEST
)
if not request.user.is_superuser:
if Job.objects.get(uid=job_uid).last_run_status == "SUBMITTED":
return Response(
{"status": "PREVIOUS_RUN_IN_QUEUE"}, status=status.HTTP_400_BAD_REQUEST
)
task_runner = ExportTaskRunner()
task_runner.run_task(job_uid=job_uid, user=request.user)
return Response({"status": "OK"}, status=status.HTTP_201_CREATED)
Expand Down

0 comments on commit 3098b06

Please sign in to comment.