Skip to content

Commit

Permalink
Add scraper timeout as API input parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
shrir committed Nov 4, 2024
1 parent 52cde78 commit 6511dd4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/domain/jobs/controllers/job_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def create_job_post_from_url(
if job_link_domain.endswith("workable.com") or job_link_domain.endswith("linkedin.com"):
render = True

html_content = await extract_url_content(data.url, render=render)
html_content = await extract_url_content(data.url, render=render, timeout=data.timeout)
job_details = await extract_job_details_from_html(html_content)

company_url = job_details.get("company", {}).get("url")
Expand Down
1 change: 1 addition & 0 deletions src/app/domain/jobs/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class JobPostCreateFromURL(CamelizedBaseStruct):
"""A job post create from URL schema."""

url: str
timeout: float = 30.0


class JobPostUpdate(CamelizedBaseStruct, omit_defaults=True):
Expand Down
4 changes: 2 additions & 2 deletions src/app/lib/scraperapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
scraper_api_key = os.environ["SCRAPERAPI_API_KEY"]


async def extract_url_content(url: str, render: bool = False) -> str:
async def extract_url_content(url: str, render: bool = False, timeout=30.0) -> str:
"""Extracts URL content using a 3rd party service"""
params = {
"api_key": scraper_api_key,
Expand All @@ -17,6 +17,6 @@ async def extract_url_content(url: str, render: bool = False) -> str:
}

async with httpx.AsyncClient() as client:
response = await client.get("https://api.scraperapi.com", params=params, timeout=30.0)
response = await client.get("https://api.scraperapi.com", params=params, timeout=timeout)
data = response.text
return data

0 comments on commit 6511dd4

Please sign in to comment.