Skip to content

Update the CLI startup service mode #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions backend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import os

from dataclasses import dataclass
from pathlib import Path
from typing import Annotated

import cappa
import uvicorn
import granian

from rich.panel import Panel
from rich.text import Text
Expand All @@ -18,6 +17,7 @@
from backend.common.enums import DataBaseType, PrimaryKeyType
from backend.common.exception.errors import BaseExceptionMixin
from backend.core.conf import settings
from backend.core.path_conf import BASE_PATH
from backend.database.db import async_db_session
from backend.plugin.tools import get_plugin_sql
from backend.utils.file_ops import install_git_plugin, install_zip_plugin, parse_sql_script
Expand All @@ -39,14 +39,18 @@ def run(host: str, port: int, reload: bool, workers: int | None) -> None:
)

console.print(Panel(panel_content, title='fba 服务信息', border_style='purple', padding=(1, 2)))
uvicorn.run(
app='backend.main:app',
host=host,
granian.Granian(
target='backend.main:app',
interface='asgi',
address=host,
port=port,
reload=not reload,
reload_excludes=[os.path.abspath('.venv' if Path(Path.cwd() / '.venv').is_dir() else '../.venv')],
workers=workers,
)
reload_ignore_paths=[
os.path.join(BASE_PATH.parent / '.venv'),
os.path.join(BASE_PATH / 'log'),
],
workers=workers or 1,
).serve()


async def install_plugin(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"fastapi[standard]==0.115.11",
"flower>=2.0.0",
"gevent>=24.11.1",
"granian>=2.4.0",
"ip2loc>=1.0.0",
"itsdangerous>=2.2.0",
"jinja2>=3.1.4",
Expand Down Expand Up @@ -62,7 +63,6 @@ lint = [
]
server = [
"aio-pika>=9.4.3",
"granian>=2.4.0",
"wait-for-it>=2.2.2",
]

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ click==8.1.8
# click-didyoumean
# click-plugins
# click-repl
# granian
# typer
# uvicorn
click-didyoumean==0.3.1
Expand Down Expand Up @@ -106,6 +107,8 @@ flower==2.0.1
# via fastapi-best-architecture
gevent==24.11.1
# via fastapi-best-architecture
granian==2.4.0
# via fastapi-best-architecture
greenlet==3.1.1
# via
# gevent
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.