π Add debug logging to JobSearchService for Remotive API responses, including URL, parameters, job count, and error handling.
9e0d988
from dotenv import load_dotenv | |
from src.config import get_settings | |
import requests | |
import json | |
import time | |
# Load environment variables from .env file | |
load_dotenv() | |
def test_remotive_api_directly(): | |
"""Test Remotive API directly to debug timeout issues.""" | |
settings = get_settings() | |
print(f"π Testing Remotive API directly...") | |
print(f"π API URL: {settings.remotive_api_url}") | |
# Test different search parameters and timeouts | |
test_cases = [ | |
{"search": "software engineer", "location": "london", "timeout": 30}, | |
{"search": "python", "location": "remote", "timeout": 30}, | |
{"search": "software", "location": "", "timeout": 30}, # No location filter | |
{"search": "", "location": "", "timeout": 30}, # No filters - get all jobs | |
] | |
for i, test_case in enumerate(test_cases, 1): | |
print( | |
f"\nπ Test {i}: search='{test_case['search']}', location='{test_case['location']}', timeout={test_case['timeout']}s" | |
) | |
try: | |
params = {} | |
if test_case["search"]: | |
params["search"] = test_case["search"] | |
if test_case["location"]: | |
params["location"] = test_case["location"] | |
print(f" π Parameters: {params}") | |
start_time = time.time() | |
response = requests.get( | |
settings.remotive_api_url, params=params, timeout=test_case["timeout"] | |
) | |
end_time = time.time() | |
response_time = end_time - start_time | |
print(f" β±οΈ Response time: {response_time:.2f}s") | |
if response.status_code == 200: | |
data = response.json() | |
jobs = data.get("jobs", []) | |
print(f" β Status: {response.status_code} | Found: {len(jobs)} jobs") | |
if jobs: | |
sample_job = jobs[0] | |
print( | |
f" π Sample: '{sample_job.get('title', 'N/A')}' at '{sample_job.get('company_name', 'N/A')}' in '{sample_job.get('candidate_required_location', 'N/A')}'" | |
) | |
break # Found some results, stop testing | |
else: | |
print(f" β οΈ Response OK but no jobs in results") | |
print(f" π Response keys: {list(data.keys())}") | |
else: | |
print( | |
f" β Status: {response.status_code} | Error: {response.text[:100]}" | |
) | |
except requests.exceptions.Timeout: | |
print(f" β±οΈ TIMEOUT after {test_case['timeout']}s") | |
except Exception as e: | |
print(f" π₯ Exception: {str(e)}") | |
def test_remotive_simple(): | |
"""Simple test without any parameters.""" | |
settings = get_settings() | |
print(f"\nπ Testing Remotive API with no parameters (should be fastest)...") | |
try: | |
start_time = time.time() | |
response = requests.get(settings.remotive_api_url, timeout=30) | |
end_time = time.time() | |
response_time = end_time - start_time | |
print(f"β±οΈ Response time: {response_time:.2f}s") | |
if response.status_code == 200: | |
data = response.json() | |
jobs = data.get("jobs", []) | |
print(f"β Success! Found {len(jobs)} total jobs available") | |
if jobs: | |
print( | |
f"π First job: '{jobs[0].get('title', 'N/A')}' at '{jobs[0].get('company_name', 'N/A')}'" | |
) | |
else: | |
print(f"β Status: {response.status_code}") | |
print(f"π Response: {response.text[:200]}") | |
except Exception as e: | |
print(f"π₯ Exception: {str(e)}") | |
if __name__ == "__main__": | |
test_remotive_simple() | |
test_remotive_api_directly() | |