File size: 3,808 Bytes
9e0d988 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
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()
|