fix(statistics): run recalculate independently
This commit is contained in:
@@ -537,7 +537,9 @@ def calculate_playtime(score: Score, beatmap_length: int) -> tuple[int, bool]:
|
|||||||
+ (score.nsmall_tick_hit or 0)
|
+ (score.nsmall_tick_hit or 0)
|
||||||
)
|
)
|
||||||
total_obj = 0
|
total_obj = 0
|
||||||
for statistics, count in score.maximum_statistics.items():
|
for statistics, count in (
|
||||||
|
score.maximum_statistics.items() if score.maximum_statistics else {}
|
||||||
|
):
|
||||||
if not isinstance(statistics, HitResult):
|
if not isinstance(statistics, HitResult):
|
||||||
statistics = HitResult(statistics)
|
statistics = HitResult(statistics)
|
||||||
if statistics.is_scorable():
|
if statistics.is_scorable():
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ scheduler: AsyncIOScheduler | None = None
|
|||||||
def init_scheduler():
|
def init_scheduler():
|
||||||
global scheduler
|
global scheduler
|
||||||
scheduler = AsyncIOScheduler(timezone=UTC)
|
scheduler = AsyncIOScheduler(timezone=UTC)
|
||||||
scheduler.start()
|
|
||||||
|
|
||||||
|
|
||||||
def get_scheduler() -> AsyncIOScheduler:
|
def get_scheduler() -> AsyncIOScheduler:
|
||||||
@@ -20,6 +19,12 @@ def get_scheduler() -> AsyncIOScheduler:
|
|||||||
return scheduler # pyright: ignore[reportReturnType]
|
return scheduler # pyright: ignore[reportReturnType]
|
||||||
|
|
||||||
|
|
||||||
|
def start_scheduler():
|
||||||
|
global scheduler
|
||||||
|
if scheduler is not None:
|
||||||
|
scheduler.start()
|
||||||
|
|
||||||
|
|
||||||
def stop_scheduler():
|
def stop_scheduler():
|
||||||
global scheduler
|
global scheduler
|
||||||
if scheduler:
|
if scheduler:
|
||||||
|
|||||||
11
main.py
11
main.py
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
@@ -7,7 +8,7 @@ import os
|
|||||||
from app.config import settings
|
from app.config import settings
|
||||||
from app.dependencies.database import engine, redis_client
|
from app.dependencies.database import engine, redis_client
|
||||||
from app.dependencies.fetcher import get_fetcher
|
from app.dependencies.fetcher import get_fetcher
|
||||||
from app.dependencies.scheduler import init_scheduler, stop_scheduler
|
from app.dependencies.scheduler import start_scheduler, stop_scheduler
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.router import (
|
from app.router import (
|
||||||
api_v1_router,
|
api_v1_router,
|
||||||
@@ -66,11 +67,9 @@ async def lifespan(app: FastAPI):
|
|||||||
# on startup
|
# on startup
|
||||||
await get_fetcher() # 初始化 fetcher
|
await get_fetcher() # 初始化 fetcher
|
||||||
await init_geoip() # 初始化 GeoIP 数据库
|
await init_geoip() # 初始化 GeoIP 数据库
|
||||||
if os.environ.get("RECALCULATE", "false").lower() == "true":
|
|
||||||
await recalculate()
|
|
||||||
await create_rx_statistics()
|
await create_rx_statistics()
|
||||||
await calculate_user_rank(True)
|
await calculate_user_rank(True)
|
||||||
init_scheduler()
|
start_scheduler()
|
||||||
schedule_geoip_updates() # 调度 GeoIP 定时更新任务
|
schedule_geoip_updates() # 调度 GeoIP 定时更新任务
|
||||||
await daily_challenge_job()
|
await daily_challenge_job()
|
||||||
await create_banchobot()
|
await create_banchobot()
|
||||||
@@ -176,6 +175,10 @@ if settings.osu_web_client_secret == "your_osu_web_client_secret_here":
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
|
if os.environ.get("RECALCULATE", "false").lower() == "true":
|
||||||
|
asyncio.run(recalculate())
|
||||||
|
exit()
|
||||||
|
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
"main:app",
|
"main:app",
|
||||||
host=settings.host,
|
host=settings.host,
|
||||||
|
|||||||
Reference in New Issue
Block a user