Add log level args for pc run (#182)
This commit is contained in:
parent
9d16582c23
commit
af9733996a
@ -63,8 +63,8 @@ API_URL = "http://localhost:8000"
|
|||||||
BUN_PATH = "$HOME/.bun/bin/bun"
|
BUN_PATH = "$HOME/.bun/bin/bun"
|
||||||
# Command to install bun.
|
# Command to install bun.
|
||||||
INSTALL_BUN = "curl https://bun.sh/install | bash"
|
INSTALL_BUN = "curl https://bun.sh/install | bash"
|
||||||
# Command to run the backend in dev mode.
|
# Default host in dev mode.
|
||||||
RUN_BACKEND = "uvicorn --log-level debug --reload --host 0.0.0.0".split()
|
BACKEND_HOST = "0.0.0.0"
|
||||||
# The default timeout when launching the gunicorn server.
|
# The default timeout when launching the gunicorn server.
|
||||||
TIMEOUT = 120
|
TIMEOUT = 120
|
||||||
# The command to run the backend in production mode.
|
# The command to run the backend in production mode.
|
||||||
@ -135,6 +135,17 @@ class Env(str, Enum):
|
|||||||
PROD = "prod"
|
PROD = "prod"
|
||||||
|
|
||||||
|
|
||||||
|
# Log levels
|
||||||
|
class LogLevel(str, Enum):
|
||||||
|
"""The log levels."""
|
||||||
|
|
||||||
|
DEBUG = "debug"
|
||||||
|
INFO = "info"
|
||||||
|
WARNING = "warning"
|
||||||
|
ERROR = "error"
|
||||||
|
CRITICAL = "critical"
|
||||||
|
|
||||||
|
|
||||||
class Endpoint(Enum):
|
class Endpoint(Enum):
|
||||||
"""Endpoints for the pynecone backend API."""
|
"""Endpoints for the pynecone backend API."""
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ def run(
|
|||||||
env: constants.Env = constants.Env.DEV,
|
env: constants.Env = constants.Env.DEV,
|
||||||
frontend: bool = True,
|
frontend: bool = True,
|
||||||
backend: bool = True,
|
backend: bool = True,
|
||||||
|
loglevel: constants.LogLevel = constants.LogLevel.ERROR,
|
||||||
):
|
):
|
||||||
"""Run the app.
|
"""Run the app.
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ def run(
|
|||||||
env: The environment to run the app in.
|
env: The environment to run the app in.
|
||||||
frontend: Whether to run the frontend.
|
frontend: Whether to run the frontend.
|
||||||
backend: Whether to run the backend.
|
backend: Whether to run the backend.
|
||||||
|
loglevel: The log level to use.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
Exit: If the app is not initialized.
|
Exit: If the app is not initialized.
|
||||||
@ -93,7 +95,7 @@ def run(
|
|||||||
if frontend:
|
if frontend:
|
||||||
frontend_cmd(app.app)
|
frontend_cmd(app.app)
|
||||||
if backend:
|
if backend:
|
||||||
backend_cmd(app.__name__)
|
backend_cmd(app.__name__, loglevel=loglevel)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
@ -13,6 +13,7 @@ import signal
|
|||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import uvicorn
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
@ -532,23 +533,29 @@ def get_num_workers() -> int:
|
|||||||
return (os.cpu_count() or 1) * 2 + 1
|
return (os.cpu_count() or 1) * 2 + 1
|
||||||
|
|
||||||
|
|
||||||
def run_backend(app_name: str):
|
def run_backend(app_name: str, loglevel: constants.LogLevel = constants.LogLevel.ERROR):
|
||||||
"""Run the backend.
|
"""Run the backend.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
app_name: The app name.
|
app_name: The app name.
|
||||||
|
loglevel: The log level.
|
||||||
"""
|
"""
|
||||||
command = constants.RUN_BACKEND + [
|
uvicorn.run(
|
||||||
f"{app_name}:{constants.APP_VAR}.{constants.API_VAR}"
|
f"{app_name}:{constants.APP_VAR}.{constants.API_VAR}",
|
||||||
]
|
host=constants.BACKEND_HOST,
|
||||||
subprocess.run(command)
|
log_level=loglevel,
|
||||||
|
reload=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_backend_prod(app_name: str):
|
def run_backend_prod(
|
||||||
|
app_name: str, loglevel: constants.LogLevel = constants.LogLevel.ERROR
|
||||||
|
):
|
||||||
"""Run the backend.
|
"""Run the backend.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
app_name: The app name.
|
app_name: The app name.
|
||||||
|
loglevel: The log level.
|
||||||
"""
|
"""
|
||||||
num_workers = get_num_workers()
|
num_workers = get_num_workers()
|
||||||
command = constants.RUN_BACKEND_PROD + [
|
command = constants.RUN_BACKEND_PROD + [
|
||||||
@ -556,6 +563,8 @@ def run_backend_prod(app_name: str):
|
|||||||
str(num_workers),
|
str(num_workers),
|
||||||
"--threads",
|
"--threads",
|
||||||
str(num_workers),
|
str(num_workers),
|
||||||
|
"--log-level",
|
||||||
|
str(loglevel),
|
||||||
f"{app_name}:{constants.APP_VAR}()",
|
f"{app_name}:{constants.APP_VAR}()",
|
||||||
]
|
]
|
||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
|
Loading…
Reference in New Issue
Block a user