Install gunicorn
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
import os
|
import os
|
||||||
import click
|
import click
|
||||||
|
import subprocess
|
||||||
import conmorfeusz.web as web
|
import conmorfeusz.web as web
|
||||||
import conmorfeusz.concraft as ccpl
|
import conmorfeusz.concraft as ccpl
|
||||||
|
from conmorfeusz.web import create_app
|
||||||
|
from conmorfeusz.server import StandaloneApplication
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option('--port', default=5000, help='Port on which the application will be listening to.')
|
@click.option("--host", default="0.0.0.0", help='Default host on which the application will be listening on.')
|
||||||
@click.option('--ccpl-port', default=3000, help='Port on which internal concraft-pl server will be listening to.')
|
@click.option('--port', default=5000, help='Port which the application will be listening on.')
|
||||||
|
@click.option("--workers", default=4, help='Number of workers used to handle incoming requests.')
|
||||||
|
@click.option('--ccpl-port', default=3000, help='Port which internal concraft-pl server will be listening on.')
|
||||||
@click.option('--ccpl-model', default=None, help='Model used by concraft-pl. It will fallback to CONCRAFT_PL_MODEL envvar if not specified.')
|
@click.option('--ccpl-model', default=None, help='Model used by concraft-pl. It will fallback to CONCRAFT_PL_MODEL envvar if not specified.')
|
||||||
@click.option('--ccpl-bin', default=None, help='Concraft-pl binary file. It will fallback to CONCRAFT_PL_BIN envvar if not specified.')
|
@click.option('--ccpl-bin', default=None, help='Concraft-pl binary file. It will fallback to CONCRAFT_PL_BIN envvar if not specified.')
|
||||||
@click.option('--ccpl-core-num', default=1, help='Number of cores used to run Concraft-pl logic.')
|
@click.option('--ccpl-core-num', default=1, help='Number of cores used to run Concraft-pl logic.')
|
||||||
@click.option('--ccpl-alloc-size', default=64, help='Allocation size for Concraft-pl.')
|
@click.option('--ccpl-alloc-size', default=64, help='Allocation size for Concraft-pl.')
|
||||||
def run(port, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccpl_alloc_size):
|
def run(host, port, workers, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccpl_alloc_size):
|
||||||
"""
|
"""
|
||||||
Glues all services together and starts the holistic app.
|
Glues all services together and starts the holistic app.
|
||||||
"""
|
"""
|
||||||
@@ -26,5 +32,11 @@ def run(port, ccpl_port, ccpl_model, ccpl_bin, ccpl_core_num, ccpl_alloc_size):
|
|||||||
|
|
||||||
concraft_cfg = (ccpl_model, ccpl_bin, ccpl_port, ccpl_core_num, ccpl_alloc_size)
|
concraft_cfg = (ccpl_model, ccpl_bin, ccpl_port, ccpl_core_num, ccpl_alloc_size)
|
||||||
|
|
||||||
with ccpl.start_server(*concraft_cfg):
|
with ccpl.start_server(*concraft_cfg):
|
||||||
web.start(port)
|
options = {
|
||||||
|
'bind': f'{host}:{port}',
|
||||||
|
'workers': workers,
|
||||||
|
}
|
||||||
|
|
||||||
|
StandaloneApplication(create_app, options).run()
|
||||||
|
|
||||||
|
|||||||
15
conmorfeusz/conmorfeusz/server/__init__.py
Normal file
15
conmorfeusz/conmorfeusz/server/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from gunicorn.app.base import BaseApplication
|
||||||
|
|
||||||
|
class StandaloneApplication(BaseApplication):
|
||||||
|
def __init__(self, app_factory, options=None):
|
||||||
|
self.options = options or {}
|
||||||
|
self.app_factory = app_factory
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
for key, value in self.options.items():
|
||||||
|
if key in self.cfg.settings and value is not None:
|
||||||
|
self.cfg.set(key.lower(), value)
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
return self.app_factory()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from conmorfeusz.web import analyzer
|
from . import analyzer
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
app = Flask(__name__, instance_relative_config=True)
|
app = Flask(__name__, instance_relative_config=True)
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
{
|
{
|
||||||
self,
|
self,
|
||||||
system,
|
|
||||||
pkgs,
|
pkgs,
|
||||||
fetchurl,
|
fetchurl,
|
||||||
libgcc,
|
libgcc,
|
||||||
stdenv,
|
stdenv,
|
||||||
autoPatchelfHook,
|
autoPatchelfHook,
|
||||||
makeWrapper,
|
makeWrapper,
|
||||||
defaultModel ? self.packages.${system}.concraft-pl-sgjp-model,
|
defaultModel ? self.packages.${stdenv.hostPlatform.system}.concraft-pl-sgjp-model,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
python = pkgs.python311; # Możesz zmienić wersję Python
|
python = pkgs.python311; # Możesz zmienić wersję Python
|
||||||
@@ -49,6 +48,7 @@ in
|
|||||||
flask
|
flask
|
||||||
requests
|
requests
|
||||||
click
|
click
|
||||||
|
gunicorn
|
||||||
];
|
];
|
||||||
|
|
||||||
nativeBuildInputs = with pythonPackages; [
|
nativeBuildInputs = with pythonPackages; [
|
||||||
@@ -60,6 +60,6 @@ in
|
|||||||
postInstall = ''
|
postInstall = ''
|
||||||
wrapProgram $out/bin/conmorfeusz \
|
wrapProgram $out/bin/conmorfeusz \
|
||||||
--set CONCRAFT_PL_MODEL "${defaultModel}" \
|
--set CONCRAFT_PL_MODEL "${defaultModel}" \
|
||||||
--set CONCRAFT_PL_BIN "${self.packages.${system}.concraft-pl}/bin/concraft-pl"
|
--set CONCRAFT_PL_BIN "${self.packages.${stdenv.hostPlatform.system}.concraft-pl}/bin/concraft-pl"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ dependencies = [
|
|||||||
"morfeusz2==1.99.12",
|
"morfeusz2==1.99.12",
|
||||||
"flask",
|
"flask",
|
||||||
"requests",
|
"requests",
|
||||||
"click"
|
"click",
|
||||||
|
"gunicorn>=21.0.0"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.setuptools.packages.find]
|
[tool.setuptools.packages.find]
|
||||||
|
|||||||
Reference in New Issue
Block a user