90 lines
2.4 KiB
Python
90 lines
2.4 KiB
Python
|
|
import requests
|
|
import time
|
|
|
|
BASE_URL = "http://localhost:8000/api"
|
|
|
|
def get_job(job_id):
|
|
try:
|
|
res = requests.get(f"{BASE_URL}/jobs/active", timeout=5)
|
|
active = res.json()
|
|
return next((j for j in active if j['id'] == job_id), None)
|
|
except:
|
|
return None
|
|
|
|
def main():
|
|
print("Triggering test job...")
|
|
try:
|
|
res = requests.post(f"{BASE_URL}/status/test-job", timeout=5)
|
|
job_id = res.json()['job_id']
|
|
print(f"Job ID: {job_id}")
|
|
except Exception as e:
|
|
print(f"FAILURE: Could not trigger job: {e}")
|
|
return
|
|
|
|
time.sleep(2)
|
|
job = get_job(job_id)
|
|
if not job:
|
|
print("FAILURE: Job not active")
|
|
return
|
|
print(f"Initial Progress: {job['progress']}%")
|
|
|
|
# PAUSE
|
|
print("Pausing job...")
|
|
requests.post(f"{BASE_URL}/jobs/{job_id}/pause")
|
|
time.sleep(1)
|
|
|
|
# Check if paused
|
|
job = get_job(job_id)
|
|
print(f"Status after pause: {job['status']}")
|
|
if job['status'] != 'paused':
|
|
print("FAILURE: Status is not 'paused'")
|
|
|
|
prog_at_pause = job['progress']
|
|
time.sleep(3)
|
|
job = get_job(job_id)
|
|
print(f"Progress after 3s pause: {job['progress']}%")
|
|
|
|
if job['progress'] != prog_at_pause:
|
|
print("FAILURE: Job continued running while paused!")
|
|
else:
|
|
print("SUCCESS: Job paused correctly.")
|
|
|
|
# RESUME
|
|
print("Resuming job...")
|
|
requests.post(f"{BASE_URL}/jobs/{job_id}/resume")
|
|
time.sleep(3)
|
|
|
|
job = get_job(job_id)
|
|
print(f"Status after resume: {job['status']}")
|
|
print(f"Progress after resume: {job['progress']}%")
|
|
|
|
if job['progress'] > prog_at_pause:
|
|
print("SUCCESS: Job resumed and progress advanced.")
|
|
else:
|
|
print("FAILURE: Job didn't advance after resume.")
|
|
|
|
# CANCEL
|
|
print("Cancelling job...")
|
|
requests.post(f"{BASE_URL}/jobs/{job_id}/cancel")
|
|
time.sleep(2)
|
|
|
|
# Should be completed/cancelled
|
|
# Wait for retention cleanup (10s) + buffer
|
|
print("Waiting for retention cleanup (12s)...")
|
|
time.sleep(12)
|
|
|
|
# Check History
|
|
print("Checking History...")
|
|
res = requests.get(f"{BASE_URL}/jobs/history")
|
|
history = res.json()
|
|
|
|
my_job = next((j for j in history if j['id'] == job_id), None)
|
|
if my_job:
|
|
print(f"SUCCESS: Job found in history. Status: {my_job['status']}")
|
|
else:
|
|
print("FAILURE: Job not found in history.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|