MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / send_and_monitor_task

Function send_and_monitor_task

scripts/server/post_multi_servers.py:34–76  ·  view source on GitHub ↗

Send task to server and monitor until completion

(url, message, task_index, complete_bar, complete_lock)

Source from the content-addressed store, hash-verified

32 else:
33 logger.warning(f"Image path not found: {image_path}")
34 return image_path
35
36
37def send_and_monitor_task(url, message, task_index, complete_bar, complete_lock):
38 """Send task to server and monitor until completion"""
39 try:
40 if "image_path" in message and message["image_path"]:
41 message["image_path"] = process_image_path(message["image_path"])
42
43 response = requests.post(f"{url}/v1/tasks/", json=message, timeout=30)
44 response.raise_for_status()
45 response_data = response.json()
46 task_id = response_data.get("task_id")
47
48 if not task_id:
49 logger.error(f"No task_id received from {url}")
50 return False
51
52 # Step 2: Monitor task status until completion
53 while True:
54 status_response = requests.get(f"{url}/v1/tasks/{task_id}/status", timeout=15)
55 status_response.raise_for_status()
56 status_data = status_response.json()
57 task_status = status_data["status"]
58
59 if task_status == "completed":
60 return True
61 if task_status in ("failed", "cancelled"):
62 logger.error(f"Task {task_index + 1} (task_id: {task_id}) {task_status}: {status_data.get('error')}")
63 return False
64 time.sleep(0.5)
65
66 except Exception as e:
67 logger.error(f"Task {task_index + 1} at {url} failed: {e}")
68 return False
69 finally:
70 if complete_bar is not None and complete_lock is not None:
71 with complete_lock:
72 complete_bar.update(1)
73
74
75def get_available_urls(urls):
76 """Check which URLs are available and return the list"""
77 available_urls = []
78 for url in urls:
79 try:

Callers

nothing calls this directly

Calls 5

process_image_pathFunction · 0.85
postMethod · 0.80
errorMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected