handle container launch failure reporting
This commit is contained in:
@@ -18,26 +18,22 @@ def register_socketio_handlers(socketio):
|
||||
|
||||
@socketio.on("docker_event")
|
||||
def handle_docker_event(data):
|
||||
"""
|
||||
Handle Docker events received from the worker.
|
||||
Extract relevant data and log it to the console.
|
||||
"""
|
||||
"""Process docker-related status events arriving from workers."""
|
||||
try:
|
||||
# Extract relevant data from the event
|
||||
worker_id = data.get("worker_id")
|
||||
event_type = data.get("type")
|
||||
event_type = data.get("type") # e.g. docker_start, docker_die, docker_launch_failed
|
||||
details = data.get("details", {})
|
||||
|
||||
container_id = details.get("container_id")
|
||||
system_container_id = details.get("system_container_id")
|
||||
container_name = details.get("container_name")
|
||||
unix_timestamp = details.get("timestamp")
|
||||
timestamp=datetime.utcfromtimestamp(unix_timestamp).isoformat()
|
||||
timestamp = datetime.utcfromtimestamp(unix_timestamp).isoformat()
|
||||
status = details.get("details", {}).get("status")
|
||||
image = details.get("details", {}).get("from")
|
||||
action = details.get("details", {}).get("Action")
|
||||
|
||||
# Log the extracted data
|
||||
# ----------------- logging boilerplate ----------------------- #
|
||||
logger.info(f"Received Docker event from worker {worker_id}:")
|
||||
logger.info(f" Event Type: {event_type}")
|
||||
logger.info(f" Docker Container ID: {container_id}")
|
||||
@@ -47,73 +43,36 @@ def register_socketio_handlers(socketio):
|
||||
logger.info(f" Status: {status}")
|
||||
logger.info(f" Image: {image}")
|
||||
logger.info(f" Action: {action}")
|
||||
|
||||
# Optionally, log the full details for debugging purposes
|
||||
logger.debug(f"Full event details: {data}")
|
||||
|
||||
if event_type=="docker_start":
|
||||
#Send the update to the API Server
|
||||
# system_container_id
|
||||
# worker_id
|
||||
# state="started"
|
||||
# timestamp
|
||||
action_URL=f"workloads/containers/status_update/{system_container_id}"
|
||||
logger.debug(f"Sending task update payload to API server for Container ID {system_container_id}")
|
||||
# ------------------- status-update calls --------------------- #
|
||||
if event_type in (
|
||||
"docker_start",
|
||||
"docker_destroy",
|
||||
"docker_die",
|
||||
"docker_launch_failed", # ← NEW
|
||||
):
|
||||
action_URL = f"workloads/containers/status_update/{system_container_id}"
|
||||
new_status_map = {
|
||||
"docker_start": "running",
|
||||
"docker_destroy": "deleted",
|
||||
"docker_die": "dead",
|
||||
"docker_launch_failed": "launch_failed", # NEW
|
||||
}
|
||||
payload = {
|
||||
"new_status": new_status_map[event_type],
|
||||
"system_container_id": system_container_id,
|
||||
"worker_id": worker_id,
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
headers = {"Content-Type": "application/json"}
|
||||
websocket_server_response = requests.put(
|
||||
f"{api_server_url}/{action_URL}",
|
||||
data=json.dumps(payload),
|
||||
headers=headers,
|
||||
)
|
||||
logger.debug(websocket_server_response)
|
||||
logger.info("Update complete")
|
||||
|
||||
payload = {
|
||||
"new_status": "running",
|
||||
"system_container_id": system_container_id,
|
||||
"worker_id": worker_id,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
websocket_server_response = requests.put(f"{api_server_url}/{action_URL}", data=json.dumps(payload), headers=headers)
|
||||
logger.debug( websocket_server_response)
|
||||
logger.info("Update complete")
|
||||
|
||||
if event_type=="docker_destroy":
|
||||
#Send the update to the API Server
|
||||
# system_container_id
|
||||
# worker_id
|
||||
# state="started"
|
||||
# timestamp
|
||||
action_URL=f"workloads/containers/status_update/{system_container_id}"
|
||||
logger.debug(f"Sending task update payload to API server for Container ID {system_container_id}")
|
||||
|
||||
payload = {
|
||||
"new_status": "deleted",
|
||||
"system_container_id": system_container_id,
|
||||
"worker_id": worker_id,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
websocket_server_response = requests.put(f"{api_server_url}/{action_URL}", data=json.dumps(payload), headers=headers)
|
||||
logger.debug( websocket_server_response)
|
||||
logger.info("Update complete")
|
||||
|
||||
if event_type=="docker_die":
|
||||
#Send the update to the API Server
|
||||
# system_container_id
|
||||
# worker_id
|
||||
# state="started"
|
||||
# timestamp
|
||||
action_URL=f"workloads/containers/status_update/{system_container_id}"
|
||||
logger.debug(f"Sending task update payload to API server for Container ID {system_container_id}")
|
||||
|
||||
payload = {
|
||||
"new_status": "dead",
|
||||
"system_container_id": system_container_id,
|
||||
"worker_id": worker_id,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
|
||||
headers = {"Content-Type": "application/json"}
|
||||
websocket_server_response = requests.put(f"{api_server_url}/{action_URL}", data=json.dumps(payload), headers=headers)
|
||||
logger.debug( websocket_server_response)
|
||||
logger.info("Update complete")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing Docker event: {e}")
|
||||
|
||||
logger.error(f"Error processing Docker event: {e}")
|
||||
Reference in New Issue
Block a user