|
|
@ -1,12 +1,10 @@ |
|
|
|
import argparse |
|
|
|
import multiprocessing |
|
|
|
import os |
|
|
|
import platform |
|
|
|
import subprocess |
|
|
|
import sys |
|
|
|
|
|
|
|
import gunicorn.app.base |
|
|
|
import gunicorn.util |
|
|
|
|
|
|
|
from .app.celery import app |
|
|
|
|
|
|
|
base = os.path.abspath(os.path.dirname(__file__)) |
|
|
@ -18,21 +16,38 @@ def number_of_workers(): |
|
|
|
return (multiprocessing.cpu_count() * 2) + 1 |
|
|
|
|
|
|
|
|
|
|
|
class StandaloneApplication(gunicorn.app.base.BaseApplication): |
|
|
|
def run_on_windows(args): |
|
|
|
import gunicorn.app.base |
|
|
|
import gunicorn.util |
|
|
|
|
|
|
|
class StandaloneApplication(gunicorn.app.base.BaseApplication): |
|
|
|
|
|
|
|
def __init__(self, options=None): |
|
|
|
self.options = options or {} |
|
|
|
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): |
|
|
|
sys.path.append(base) |
|
|
|
return gunicorn.util.import_app('app.wsgi') |
|
|
|
|
|
|
|
def __init__(self, options=None): |
|
|
|
self.options = options or {} |
|
|
|
super().__init__() |
|
|
|
options = { |
|
|
|
'bind': '%s:%s' % ('0.0.0.0', args.port), |
|
|
|
'workers': number_of_workers(), |
|
|
|
'chdir': base |
|
|
|
} |
|
|
|
StandaloneApplication(options).run() |
|
|
|
|
|
|
|
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): |
|
|
|
sys.path.append(base) |
|
|
|
return gunicorn.util.import_app('app.wsgi') |
|
|
|
def run_on_nix(args): |
|
|
|
from waitress import serve |
|
|
|
from app.wsgi import application |
|
|
|
serve(application, port=args.port) |
|
|
|
|
|
|
|
|
|
|
|
def command_db_init(args): |
|
|
@ -53,12 +68,10 @@ def command_user_create(args): |
|
|
|
|
|
|
|
def command_run_webserver(args): |
|
|
|
print(f'Starting server with port {args.port}.') |
|
|
|
options = { |
|
|
|
'bind': '%s:%s' % ('0.0.0.0', args.port), |
|
|
|
'workers': number_of_workers(), |
|
|
|
'chdir': base |
|
|
|
} |
|
|
|
StandaloneApplication(options).run() |
|
|
|
if platform.system() == 'Windows': |
|
|
|
run_on_windows(args) |
|
|
|
else: |
|
|
|
run_on_nix(args) |
|
|
|
|
|
|
|
|
|
|
|
def command_run_task_queue(args): |
|
|
|