Skip to content

Commit

Permalink
新增:API管理器(仅基本架构)
Browse files Browse the repository at this point in the history
  • Loading branch information
XYCode-Kerman committed Mar 25, 2024
1 parent 5b7f51e commit bc9a1f3
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 477 deletions.
1 change: 1 addition & 0 deletions .github/workflows/autotest.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
name: AutoTest
on: [push, pull_request]

jobs:
Expand Down
9 changes: 3 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import pathlib

from ccf_parser import CCF
from judge import start_judging
from manager import start_server_background

ccf = CCF(
**json.loads(pathlib.Path('./temp/test_contest/ccf.json').read_text(encoding='utf-8'))
)

start_judging(ccf)
if '__main__' == __name__:
start_server_background()
1 change: 1 addition & 0 deletions manager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .base import start_server_background
1 change: 1 addition & 0 deletions manager/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .base import app
6 changes: 6 additions & 0 deletions manager/api/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import fastapi

from .routers import base_router

app = fastapi.FastAPI()
app.include_router(base_router)
1 change: 1 addition & 0 deletions manager/api/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .base import router as base_router
19 changes: 19 additions & 0 deletions manager/api/routers/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import datetime

from fastapi import APIRouter

router = APIRouter(prefix='/base', tags=['基本'])


@router.get('/ping', responses={
200: {
'description': 'Ping 服务器,获取一些基本信息',
'content': {
'application/json': {
'example': {'message': 'pong', 'server_time': '2024-03-25T23:39:25.899385'}
}
}
}
})
async def ping():
return {'message': 'pong', 'server_time': datetime.datetime.now().isoformat()}
19 changes: 19 additions & 0 deletions manager/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import atexit
import pathlib
import threading

import uvicorn

from utils import manager_logger

from .api import app as api


def _start_server():
uvicorn.run(api, host="0.0.0.0", port=2568)


def start_server_background():
server_thread = threading.Thread(
target=_start_server)
server_thread.start()
1,132 changes: 661 additions & 471 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ readme = "README.md"
python = ">=3.10"
rich = "^13.7.1"
pydantic = "^2.6.4"
typer = "^0.10.0"
fastapi = "^0.110.0"
uvicorn = "^0.29.0"


[[tool.poetry.source]]
Expand Down

0 comments on commit bc9a1f3

Please sign in to comment.