Skip to content

Commit e84ef04

Browse files
authored
Update the CLI startup service mode (#718)
1 parent adee3a2 commit e84ef04

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

backend/cli.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
import os
55

66
from dataclasses import dataclass
7-
from pathlib import Path
87
from typing import Annotated
98

109
import cappa
11-
import uvicorn
10+
import granian
1211

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

4141
console.print(Panel(panel_content, title='fba 服务信息', border_style='purple', padding=(1, 2)))
42-
uvicorn.run(
43-
app='backend.main:app',
44-
host=host,
42+
granian.Granian(
43+
target='backend.main:app',
44+
interface='asgi',
45+
address=host,
4546
port=port,
4647
reload=not reload,
47-
reload_excludes=[os.path.abspath('.venv' if Path(Path.cwd() / '.venv').is_dir() else '../.venv')],
48-
workers=workers,
49-
)
48+
reload_ignore_paths=[
49+
os.path.join(BASE_PATH.parent / '.venv'),
50+
os.path.join(BASE_PATH / 'log'),
51+
],
52+
workers=workers or 1,
53+
).serve()
5054

5155

5256
async def install_plugin(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"fastapi[standard]==0.115.11",
3333
"flower>=2.0.0",
3434
"gevent>=24.11.1",
35+
"granian>=2.4.0",
3536
"ip2loc>=1.0.0",
3637
"itsdangerous>=2.2.0",
3738
"jinja2>=3.1.4",
@@ -62,7 +63,6 @@ lint = [
6263
]
6364
server = [
6465
"aio-pika>=9.4.3",
65-
"granian>=2.4.0",
6666
"wait-for-it>=2.2.2",
6767
]
6868

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ click==8.1.8
5757
# click-didyoumean
5858
# click-plugins
5959
# click-repl
60+
# granian
6061
# typer
6162
# uvicorn
6263
click-didyoumean==0.3.1
@@ -106,6 +107,8 @@ flower==2.0.1
106107
# via fastapi-best-architecture
107108
gevent==24.11.1
108109
# via fastapi-best-architecture
110+
granian==2.4.0
111+
# via fastapi-best-architecture
109112
greenlet==3.1.1
110113
# via
111114
# gevent

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)