Repository navigation
Expand file tree
/
Copy pathtest_persistent_jobs.py
More file actions
132 lines (100 loc) Β· 4.57 KB
/
Copy pathtest_persistent_jobs.py
File metadata and controls
132 lines (100 loc) Β· 4.57 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python3
"""
Test script to verify persistent job status storage.
This script tests that job status information is saved to JSON files
and can be loaded back after server restart.
"""
import asyncio
import httpx
import json
import time
from pathlib import Path
# API base URL
BASE_URL = "http://localhost:8000/api/v1/gap-analysis"
async def test_persistent_job_storage():
"""
Test that job status is saved to persistent storage.
"""
print("π§ͺ TESTING PERSISTENT JOB STATUS STORAGE")
print("=" * 50)
async with httpx.AsyncClient(timeout=300.0) as client:
# Step 1: Submit a job
print("\nπ€ Step 1: Submitting gap analysis job...")
submission_data = {
"url": "https://arxiv.org/pdf/2506.15524",
"max_papers": 3, # Small for testing
"validation_threshold": 1
}
try:
submit_response = await client.post(
f"{BASE_URL}/submit",
json=submission_data
)
if submit_response.status_code == 200:
submission_result = submit_response.json()
job_id = submission_result["job_id"]
print(f"β
Job submitted successfully!")
print(f" Job ID: {job_id}")
else:
print(f"β Job submission failed: {submit_response.status_code}")
print(f" Error: {submit_response.text}")
return
except Exception as e:
print(f"β Job submission error: {str(e)}")
return
# Step 2: Check if job status file was created
print(f"\nπ Step 2: Checking persistent storage...")
jobs_dir = Path("gap_analysis_jobs")
job_file = jobs_dir / f"job_{job_id}.json"
if job_file.exists():
print(f"β
Job status file created: {job_file}")
# Read and display the job status file
with open(job_file, 'r') as f:
job_data = json.load(f)
print(f" Status: {job_data['status']}")
print(f" Created: {job_data['created_at']}")
print(f" Progress: {job_data['progress_message']}")
print(f" URL: {job_data['request']['url']}")
else:
print(f"β Job status file not found: {job_file}")
# Step 3: Check the /jobs endpoint
print(f"\nπ Step 3: Checking /jobs endpoint...")
try:
jobs_response = await client.get(f"{BASE_URL}/jobs?limit=10")
if jobs_response.status_code == 200:
jobs = jobs_response.json()
print(f"β
Found {len(jobs)} jobs in /jobs endpoint")
# Find our job
our_job = None
for job in jobs:
if job["job_id"] == job_id:
our_job = job
break
if our_job:
print(f"β
Our job found in /jobs endpoint:")
print(f" Status: {our_job['status']}")
print(f" Progress: {our_job['progress_message']}")
else:
print(f"β Our job not found in /jobs endpoint")
else:
print(f"β Failed to get jobs: {jobs_response.status_code}")
except Exception as e:
print(f"β Error getting jobs: {str(e)}")
# Step 4: Check health endpoint for storage info
print(f"\nπ₯ Step 4: Checking health endpoint...")
try:
health_response = await client.get(f"{BASE_URL}/health")
if health_response.status_code == 200:
health_data = health_response.json()
print(f"β
Health check successful:")
print(f" Status: {health_data['status']}")
print(f" Total jobs: {health_data['total_jobs']}")
print(f" Running jobs: {health_data['running_jobs']}")
else:
print(f"β Health check failed: {health_response.status_code}")
except Exception as e:
print(f"β Error checking health: {str(e)}")
print(f"\nπ― TEST COMPLETED")
print(f"Job status should now be persisted in: {job_file}")
if __name__ == "__main__":
asyncio.run(test_persistent_job_storage())