Spaces:
Running
Running
Implement asynchronous mail collection and improve error logging; make query optional in MailReqData
Browse files- app/router/mail.py +5 -2
- app/schema/__init__.py +1 -1
app/router/mail.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
"""Module for defining the main routes of the API."""
|
2 |
import os
|
3 |
import pickle
|
|
|
|
|
4 |
from fastapi import APIRouter, Request
|
5 |
from fastapi.responses import JSONResponse
|
6 |
|
@@ -38,9 +40,10 @@ def collect(query: MailReqData, request: Request):
|
|
38 |
scopes=cred_dict["scopes"],
|
39 |
)
|
40 |
mailservice = build("gmail", "v1", credentials=credentials)
|
41 |
-
mail.collect(mailservice, query.query)
|
42 |
-
return JSONResponse(content={"message": "Mail
|
43 |
except Exception as e:
|
|
|
44 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
45 |
|
46 |
# @router.get("")
|
|
|
1 |
"""Module for defining the main routes of the API."""
|
2 |
import os
|
3 |
import pickle
|
4 |
+
import threading
|
5 |
+
from venv import logger
|
6 |
from fastapi import APIRouter, Request
|
7 |
from fastapi.responses import JSONResponse
|
8 |
|
|
|
40 |
scopes=cred_dict["scopes"],
|
41 |
)
|
42 |
mailservice = build("gmail", "v1", credentials=credentials)
|
43 |
+
threading.Thread(target=mail.collect, args=(mailservice, query.query)).start()
|
44 |
+
return JSONResponse(content={"message": "Mail collection in progress."})
|
45 |
except Exception as e:
|
46 |
+
logger.error("Error collecting mail: %s", e)
|
47 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
48 |
|
49 |
# @router.get("")
|
app/schema/__init__.py
CHANGED
@@ -28,7 +28,7 @@ class MailReqData(BaseModel):
|
|
28 |
query (str): The query or message content sent by the user.
|
29 |
"""
|
30 |
email: str
|
31 |
-
query: str
|
32 |
|
33 |
class ReqFollowUp(BaseModel):
|
34 |
"""
|
|
|
28 |
query (str): The query or message content sent by the user.
|
29 |
"""
|
30 |
email: str
|
31 |
+
query: Optional[str] = ""
|
32 |
|
33 |
class ReqFollowUp(BaseModel):
|
34 |
"""
|