Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set timeout parameter on linkchecker and update fastApi #17

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ async def get_status_for_url(item):
data = await fetch_data(query=query, values={'item': decoded_item })
return data

# Endpoint to retrieve URLs that that timed out. Timeout is set to 5 seconds currently
@app.get('/Timeout_URLs', response_model=List[StatusResponse])
async def get_timeout_urls():
query = """
SELECT DISTINCT *
FROM linkchecker_output
WHERE valid LIKE '%ReadTimeout%' OR valid LIKE '%ConnectTimeout%'
"""
data = await fetch_data(query=query)
return data

@app.get("/Single_url_status_history", response_model=List[URLAvailabilityResponse])
async def get_current_url_status_history(
url: str = Query(..., description="URL to get avalability"),
Expand Down
5 changes: 3 additions & 2 deletions src/linkchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
base = os.environ.get("OGCAPI_URL") or "https://demo.pycsw.org/gisdata"
collection = os.environ.get("OGCAPI_COLLECTION") or "metadata:main"

# Remove comment'
catalogue_json_url = base + "collections/" + collection + "/items?f=json"
# format catalogue path with f-string
catalogue_json_url= f"{base}/collections/{collection}/items?f=json"

def setup_database():
conn = psycopg2.connect(
Expand Down Expand Up @@ -124,6 +124,7 @@ def run_linkchecker(urls):
"--verbose",
"--check-extern",
"--recursion-level=1",
"--timeout=5",
"--output=csv",
url + "?f=html"
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down