save user queries in redis so that user can refresh the page and still come back to their latest task
This commit is contained in:
parent
a055c92dea
commit
d4b22deda0
7 changed files with 114 additions and 4 deletions
|
|
@ -16,6 +16,7 @@ from fastapi import Depends, FastAPI, HTTPException, Query
|
|||
from api.auth import User
|
||||
from models.listing import QueryParameters
|
||||
from rec import districts
|
||||
from redis_repository import RedisRepository
|
||||
from repositories.listing_repository import ListingRepository
|
||||
from repositories.listing_repository import ListingRepository
|
||||
from database import engine
|
||||
|
|
@ -27,6 +28,7 @@ from alembic import command
|
|||
from alembic.config import Config
|
||||
from contextlib import asynccontextmanager
|
||||
from celery.exceptions import TaskRevokedError
|
||||
from celery_app import app as celery_app
|
||||
|
||||
load_dotenv()
|
||||
logger = logging.getLogger("uvicorn")
|
||||
|
|
@ -86,6 +88,9 @@ async def refresh_listings(
|
|||
args=(query_parameters.model_dump_json(),),
|
||||
expires=expiry_time,
|
||||
)
|
||||
|
||||
redis_repository = RedisRepository.instance()
|
||||
redis_repository.add_task_for_user(user, task.id)
|
||||
return {"task_id": task.id}
|
||||
|
||||
|
||||
|
|
@ -107,6 +112,15 @@ async def get_task_status(
|
|||
}
|
||||
|
||||
|
||||
@app.get("/api/tasks_for_user")
|
||||
async def get_tasks_for_user(
|
||||
user: Annotated[User, Depends(get_current_user)],
|
||||
) -> list[str]:
|
||||
redis_repository = RedisRepository.instance()
|
||||
user_tasks = redis_repository.get_tasks_for_user(user)
|
||||
return user_tasks
|
||||
|
||||
|
||||
@app.get("/api/get_districts")
|
||||
async def get_districts(
|
||||
user: Annotated[User, Depends(get_current_user)],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue