Spaces:
Sleeping
Sleeping
Avinash commited on
Commit ·
2a31909
1
Parent(s): 61c8625
refactor: lazy-load GmailClient to decouple API startup
Browse files- backend/api.py +3 -4
backend/api.py
CHANGED
|
@@ -10,8 +10,6 @@ from fastapi import FastAPI, HTTPException
|
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
from fastapi.responses import FileResponse, PlainTextResponse
|
| 12 |
|
| 13 |
-
from backend.worker.gmail_client import GmailClient
|
| 14 |
-
|
| 15 |
app = FastAPI(title="PDF Trainer API", version="1.0")
|
| 16 |
|
| 17 |
# Allow Vite dev server
|
|
@@ -37,7 +35,8 @@ CREDENTIALS_JSON = Path(os.environ.get("GMAIL_CREDENTIALS_JSON", str(BACKEND_DIR
|
|
| 37 |
TOKEN_JSON = Path(os.environ.get("GMAIL_TOKEN_JSON", str(BACKEND_DIR / "token.json")))
|
| 38 |
|
| 39 |
|
| 40 |
-
def _gmail() ->
|
|
|
|
| 41 |
return GmailClient(CREDENTIALS_JSON, TOKEN_JSON)
|
| 42 |
|
| 43 |
|
|
@@ -210,4 +209,4 @@ async def notify_unknown(payload: Dict[str, Any]):
|
|
| 210 |
|
| 211 |
@app.get("/", response_class=PlainTextResponse)
|
| 212 |
def root():
|
| 213 |
-
return "PDF Trainer API. Use /health"
|
|
|
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
from fastapi.responses import FileResponse, PlainTextResponse
|
| 12 |
|
|
|
|
|
|
|
| 13 |
app = FastAPI(title="PDF Trainer API", version="1.0")
|
| 14 |
|
| 15 |
# Allow Vite dev server
|
|
|
|
| 35 |
TOKEN_JSON = Path(os.environ.get("GMAIL_TOKEN_JSON", str(BACKEND_DIR / "token.json")))
|
| 36 |
|
| 37 |
|
| 38 |
+
def _gmail() ->GmailClient:
|
| 39 |
+
from backend.worker.gmail_client import GmailClient
|
| 40 |
return GmailClient(CREDENTIALS_JSON, TOKEN_JSON)
|
| 41 |
|
| 42 |
|
|
|
|
| 209 |
|
| 210 |
@app.get("/", response_class=PlainTextResponse)
|
| 211 |
def root():
|
| 212 |
+
return "PDF Trainer API. Use /health"
|