File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
src/aleph/sdk/client/services Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 1- from typing import TYPE_CHECKING
1+ from typing import TYPE_CHECKING , Optional
22
33import aiohttp
4+ from aiohttp import ClientResponseError
45from aleph_message .models import ItemHash
56
67from 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
You can’t perform that action at this time.
0 commit comments