This repository has been archived on 2023-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
takahe/stator/views.py

24 lines
729 B
Python
Raw Normal View History

2022-11-19 01:24:43 +01:00
from django.conf import settings
from django.http import HttpResponse, HttpResponseForbidden
from django.views import View
2022-11-19 01:24:43 +01:00
from stator.models import StatorModel
from stator.runner import StatorRunner
class RequestRunner(View):
"""
Runs a Stator runner within a HTTP request. For when you're on something
serverless.
"""
async def get(self, request):
2022-11-19 01:24:43 +01:00
# Check the token, if supplied
if settings.STATOR_TOKEN:
if request.GET.get("token") != settings.STATOR_TOKEN:
return HttpResponseForbidden()
# Run on all models
runner = StatorRunner(StatorModel.subclasses)
handled = await runner.run()
return HttpResponse(f"Handled {handled}")