feat: add public monitor API + admin provider/server management scaffold
This commit is contained in:
22
app/main.py
22
app/main.py
@@ -34,6 +34,7 @@ from app.api.routers.users import router as users_router
|
||||
from app.api.routers.comments import router as comments_router
|
||||
from app.api.routers.webhooks import router as webhooks_router
|
||||
from app.api.routers.misc import router as misc_router
|
||||
from app.api.routers.monitor import router as monitor_router
|
||||
|
||||
app.include_router(auth_router)
|
||||
app.include_router(issues_router)
|
||||
@@ -42,12 +43,13 @@ app.include_router(users_router)
|
||||
app.include_router(comments_router)
|
||||
app.include_router(webhooks_router)
|
||||
app.include_router(misc_router)
|
||||
app.include_router(monitor_router)
|
||||
|
||||
# Run database migration on startup
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
from app.core.config import Base, engine, SessionLocal
|
||||
from app.models import webhook, apikey, activity, milestone, notification, worklog
|
||||
from app.models import webhook, apikey, activity, milestone, notification, worklog, monitor
|
||||
Base.metadata.create_all(bind=engine)
|
||||
|
||||
# Initialize from AbstractWizard (admin user, default project, etc.)
|
||||
@@ -57,3 +59,21 @@ def startup():
|
||||
run_init(db)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
# Start lightweight monitor polling thread (every 10 minutes)
|
||||
import threading, time
|
||||
from app.services.monitoring import refresh_provider_usage_once
|
||||
|
||||
def _monitor_poll_loop():
|
||||
while True:
|
||||
db2 = SessionLocal()
|
||||
try:
|
||||
refresh_provider_usage_once(db2)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
db2.close()
|
||||
time.sleep(600)
|
||||
|
||||
t = threading.Thread(target=_monitor_poll_loop, daemon=True)
|
||||
t.start()
|
||||
|
||||
Reference in New Issue
Block a user