[docs]classWarmupFailure(Exception):"""Exception to capture WarmupFailure."""pass
[docs]defwsgi_healthcheck(app:WSGIHandler,url:str,ok_status:int=200)->None:"""Simple healthcheck function."""try:host=settings.ALLOWED_HOSTS[0]ifhost.startswith("."):host="example"+hostelifhost=="*":host="testserver"headers={"HTTP_HOST":host}except(AttributeError,IndexError):headers={}warmup=app.get_response(RequestFactory().get(url,**headers))ifwarmup.status_code!=ok_status:raiseWarmupFailure(f"WSGI warmup using endpoint {url} responded with a {warmup.status_code}.")
[docs]defwsgi_app_name()->str:"""Get the WSGI name from settings."""return":".join(settings.WSGI_APPLICATION.rsplit(".",1))
[docs]defasgi_app_name()->str:"""Get the ASGI name from settings."""return":".join(settings.ASGI_APPLICATION.rsplit(".",1))