[docs]classBaseProcessBackend:""" Base class to configure an individual process backend. You are required to override ``start_server`` in the subclass. Most backends should subclass :class:`BaseServerBackend` (for web/ASGI/WSGI servers) or :class:`BaseWorkerBackend` (for background task workers) rather than this class directly so the ``server`` and ``worker`` management commands can tell the two apart. { "BACKEND": "django_prodserver.backends.servers.gunicorn.GunicornServer", "ARGS": {"bind": "0.0.0.0:8111"} } """def__init__(self,**server_args:Any)->None:self.args=self._format_server_args_from_dict(server_args.get("ARGS",{}))
[docs]defstart_server(self,*args:str)->None:""" Function is called to start the process directly. This must be implemented in the subclass """raiseNotImplementedError
[docs]defprep_server_args(self)->list[str]:""" Here we customisation of the arguments passed to the server process. Typically this is where fixed arguments are inserted into the args """returnself.args
def_format_server_args_from_dict(self,args:str|Mapping[str,str|Collection[str]|None])->list[str]:""" Formatting server process arguments coming from settings. This function transforms the dictionary settings configuration from: { "bind": "0.0.0.0:8111", "preload": None, } to [ "--bind=0.0.0.0:8111", "--preload", ] """ifisinstance(args,str):return[args]defformat_arg(arg_name:str,arg_value:str|Collection[str]|None)->str:ifarg_valueisNone:returnf"--{arg_name}"returnf"--{arg_name}={arg_value}"return[format_arg(arg_name,arg_value)forarg_name,arg_valueinargs.items()]
# def run_from_argv(self, argv):# TODO: The below should be looked into and implemented# if getattr(settings, "WEBSERVER_WARMUP", True):# app = get_internal_wsgi_application()# if getattr(settings, "WEBSERVER_WARMUP_HEALTHCHECK", None):# wsgi_healthcheck(app, settings.WEBSERVER_WARMUP_HEALTHCHECK)# # self.start_server(*self.prep_server_args())
[docs]classBaseServerBackend(BaseProcessBackend):""" Base class for web server backends (WSGI / ASGI). Backends that subclass this are runnable via ``python manage.py server``. """
[docs]classBaseWorkerBackend(BaseProcessBackend):""" Base class for background task worker backends. Backends that subclass this are runnable via ``python manage.py worker``. """