Skip to content

Commit c8b05f1

Browse files
committed
fix: scheduler service get_allocation to handle 404
1 parent 8e07661 commit c8b05f1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/aleph/sdk/client/services/scheduler.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from typing import TYPE_CHECKING
1+
from typing import TYPE_CHECKING, Optional
22

33
import aiohttp
4+
from aiohttp import ClientResponseError
45
from aleph_message.models import ItemHash
56

67
from aleph.sdk.conf import settings
@@ -40,15 +41,18 @@ async def get_nodes(self) -> SchedulerNodes:
4041

4142
return SchedulerNodes.model_validate(raw)
4243

43-
async def get_allocation(self, vm_hash: ItemHash) -> AllocationItem:
44+
async def get_allocation(self, vm_hash: ItemHash) -> Optional[AllocationItem]:
4445
"""
4546
Fetch allocation information for a given VM hash.
4647
"""
4748
url = f"{sanitize_url(settings.SCHEDULER_URL)}/api/v0/allocation/{vm_hash}"
48-
49-
async with aiohttp.ClientSession() as session:
50-
async with session.get(url) as resp:
51-
resp.raise_for_status()
52-
payload = await resp.json()
53-
54-
return AllocationItem.model_validate(payload)
49+
try:
50+
async with aiohttp.ClientSession() as session:
51+
async with session.get(url) as resp:
52+
resp.raise_for_status()
53+
payload = await resp.json()
54+
return AllocationItem.model_validate(payload)
55+
except ClientResponseError as e:
56+
if e.status == 404: # Allocation can't be find on scheduler
57+
return None
58+
raise e

0 commit comments

Comments
 (0)