feat: 添加web服务器gunicorn
This commit is contained in:
parent
4d8ac28674
commit
16851592c3
45
apps/common/management/commands/gunicorn.py
Normal file
45
apps/common/management/commands/gunicorn.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
"""
|
||||||
|
@project: MaxKB
|
||||||
|
@Author:虎
|
||||||
|
@file: gunicorn.py
|
||||||
|
@date:2024/7/19 17:43
|
||||||
|
@desc:
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from smartdoc.const import BASE_DIR
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'My custom command'
|
||||||
|
|
||||||
|
# 参数设定
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument('-b', nargs='+', type=str, help="端口:0.0.0.0:8080") # 0.0.0.0:8080
|
||||||
|
parser.add_argument('-k', nargs='?', type=str,
|
||||||
|
help="workers处理器:uvicorn.workers.UvicornWorker") # uvicorn.workers.UvicornWorker
|
||||||
|
parser.add_argument('-w', action='append', type=str, help='worker 数量') # worker 数量
|
||||||
|
parser.add_argument('--max-requests', action='append', type=str, help="最大请求") # 10240
|
||||||
|
parser.add_argument('--max-requests-jitter', action='append', type=str)
|
||||||
|
parser.add_argument('--access-logformat', action='append', type=str) # %(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
log_format = '%(h)s %(t)s %(L)ss "%(r)s" %(s)s %(b)s '
|
||||||
|
cmd = [
|
||||||
|
'gunicorn', 'smartdoc.asgi:application',
|
||||||
|
'-b', options.get('b') if options.get('b') is not None else '0.0.0.0:8080',
|
||||||
|
'-k', options.get('k') if options.get('k') is not None else 'uvicorn.workers.UvicornWorker',
|
||||||
|
'-w', options.get('w') if options.get('w') is not None else '5',
|
||||||
|
'--max-requests', options.get('max_requests') if options.get('max_requests') is not None else '10240',
|
||||||
|
'--max-requests-jitter',
|
||||||
|
options.get('max_requests_jitter') if options.get('max_requests_jitter') is not None else '2048',
|
||||||
|
'--access-logformat',
|
||||||
|
options.get('access_logformat') if options.get('access_logformat') is not None else log_format,
|
||||||
|
'--access-logfile', '-'
|
||||||
|
]
|
||||||
|
kwargs = {'cwd': BASE_DIR}
|
||||||
|
subprocess.run(cmd, **kwargs)
|
||||||
@ -38,7 +38,8 @@ INSTALLED_APPS = [
|
|||||||
'rest_framework',
|
'rest_framework',
|
||||||
"drf_yasg", # swagger 接口
|
"drf_yasg", # swagger 接口
|
||||||
'django_filters', # 条件过滤
|
'django_filters', # 条件过滤
|
||||||
'django_apscheduler'
|
'django_apscheduler',
|
||||||
|
'common'
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
9
main.py
9
main.py
@ -43,7 +43,10 @@ def perform_db_migrate():
|
|||||||
|
|
||||||
|
|
||||||
def start_services():
|
def start_services():
|
||||||
management.call_command('migrate')
|
management.call_command('gunicorn')
|
||||||
|
|
||||||
|
|
||||||
|
def runserver():
|
||||||
management.call_command('runserver', "0.0.0.0:8080")
|
management.call_command('runserver', "0.0.0.0:8080")
|
||||||
|
|
||||||
|
|
||||||
@ -70,6 +73,10 @@ if __name__ == '__main__':
|
|||||||
perform_db_migrate()
|
perform_db_migrate()
|
||||||
elif action == "collect_static":
|
elif action == "collect_static":
|
||||||
collect_static()
|
collect_static()
|
||||||
|
elif action == 'dev':
|
||||||
|
perform_db_migrate()
|
||||||
|
runserver()
|
||||||
else:
|
else:
|
||||||
collect_static()
|
collect_static()
|
||||||
|
perform_db_migrate()
|
||||||
start_services()
|
start_services()
|
||||||
|
|||||||
@ -19,7 +19,7 @@ jieba = "^0.42.1"
|
|||||||
diskcache = "^5.6.3"
|
diskcache = "^5.6.3"
|
||||||
pillow = "^10.2.0"
|
pillow = "^10.2.0"
|
||||||
filetype = "^1.2.0"
|
filetype = "^1.2.0"
|
||||||
torch = "^2.2.1"
|
torch = "2.2.1"
|
||||||
sentence-transformers = "^2.2.2"
|
sentence-transformers = "^2.2.2"
|
||||||
blinker = "^1.6.3"
|
blinker = "^1.6.3"
|
||||||
openai = "^1.13.3"
|
openai = "^1.13.3"
|
||||||
@ -42,6 +42,9 @@ websocket-client = "^1.7.0"
|
|||||||
langchain-google-genai = "^1.0.3"
|
langchain-google-genai = "^1.0.3"
|
||||||
openpyxl = "^3.1.2"
|
openpyxl = "^3.1.2"
|
||||||
xlrd = "^2.0.1"
|
xlrd = "^2.0.1"
|
||||||
|
gunicorn = "21.2.0"
|
||||||
|
python-daemon = "3.0.1"
|
||||||
|
uvicorn = "0.22.0"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user