Skip to content

Commit

Permalink
fix: check if error message is not updateing external ID message
Browse files Browse the repository at this point in the history
  • Loading branch information
mxab committed Feb 15, 2025
1 parent e989c2f commit f9fcc41
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions jupyterhub_nomad_spawner/nomad/nomad_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import Logger, LoggerAdapter
from pathlib import Path
from typing import Dict, Optional, Tuple, Union, Any
from typing import Any, Dict, Optional, Tuple, Union

from attrs import define
from httpx import AsyncClient
Expand Down Expand Up @@ -74,7 +74,10 @@ async def create_volume(
json=create_volume_json,
)
if result.is_error:
if 'ErrorCode: "AccessPointAlreadyExists"' not in result.text:
if (
'ErrorCode: "AccessPointAlreadyExists"' not in result.text
and "volume external ID cannot be updated" not in result.text
):
raise NomadException(
"Error registering volume."
+ f" status code: {result.status_code}, content: {result.text}"
Expand Down Expand Up @@ -126,7 +129,7 @@ async def job_status(self, job_id) -> str:

job_detail = response.json()
return job_detail.get("Status", "")

async def task_status(self, job_name: str) -> str:
"""Get detailed task status from most recent allocation"""
allocs = await self.client.get(f"/v1/job/{job_name}/allocations")
Expand All @@ -137,10 +140,10 @@ async def task_status(self, job_name: str) -> str:
latest_alloc = max(allocs, key=lambda x: x["CreateTime"])
if not latest_alloc:
return "pending"

task_states = latest_alloc.get("TaskStates", {}) or {}
task_states = {name: TaskState(**state) for name, state in task_states.items()}

if not task_states:
return "pending"

Expand All @@ -151,19 +154,18 @@ async def task_status(self, job_name: str) -> str:
return self._get_task_state_from_event(task)

return "running"

def _get_task_state_from_event(self, task: TaskState) -> str:
"""Determine task state from latest event"""
events = task.Events
if not events:
return "pending"

latest_event = events[-1]
if latest_event.Type in ["Driver", "Task Setup"]:
return "starting"
return "pending"


async def job_allocations(self, job_id) -> list[dict[str, Any]]:
response = await self.client.get(f"/v1/job/{job_id}/allocations")
if response.is_error:
Expand Down

0 comments on commit f9fcc41

Please sign in to comment.