-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_api.py
37 lines (27 loc) · 1.1 KB
/
main_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from gunicorn.app.base import BaseApplication
from pymicroservice.logger.logger_config import StubbedGunicornLogger
from sample.application.bootstrap import Bootstrap
GUNICORN_WORKERS = int(os.environ.get("GUNICORN_WORKERS", "1"))
PORT = int(os.environ.get("GUNICORN_PORT", "8000"))
class StandaloneApplication(BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super().__init__()
def load_config(self):
config = {key: value for key, value in self.options.items() if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def load(self):
return self.application
if __name__ == "__main__":
options = {
"bind": f"0.0.0.0:{PORT}",
"workers": GUNICORN_WORKERS,
"accesslog": "-",
"errorlog": "-",
"worker_class": "uvicorn.workers.UvicornWorker",
"logger_class": StubbedGunicornLogger,
}
StandaloneApplication(Bootstrap.build_api(production=True), options).run()