-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d8ac28
commit 1685159
Showing
4 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters