Skip to content

Commit

Permalink
app:api:routers:profile: created task for not exisiting profile and r…
Browse files Browse the repository at this point in the history
…aised 404 error
  • Loading branch information
Naveenredie15 committed Jun 21, 2024
1 parent 2e78428 commit 1b33ffe
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/utils/profile_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from app.db.mongo import profiles_collection
from app.utils.dataframes import get_dataframe_async
from app.utils.profile_segments import ProfileSegments
from fastapi import HTTPException
from app.models.prefetch import Prefetch
from app.utils.tasks import prefetch_profiles
from uuid import uuid4

setting = Settings()
logger = get_logger(__name__)
Expand Down Expand Up @@ -123,14 +127,12 @@ async def get_profile(
# {attr: description[attr] for attr in attrs.split(",")}
else:
return description[segment]

logger.info(f"Profile does not exist for: {url}")
# 1. Generate the profile from scratch
# 2. Save to MongoDB for subsequent requests
description = await save_profile(url, minimal, samples_to_show)

# Return the profile based on the segment
if segment == "description":
return await filter_descriptions_with_attrs(attrs, description)
else:
return description[segment]
logger.error(f"Profile does not exist for: {url}")
prefetch_profiles.delay(
urls=[url],
minimal=minimal,
samples_to_fetch=samples_to_show,
trigger_id=str(uuid4()),
)
raise HTTPException(status_code=404, detail="Profile does not exist for the URL")

0 comments on commit 1b33ffe

Please sign in to comment.