File tree Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Expand file tree Collapse file tree 3 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,8 @@ async def _fetch(
114
114
if isinstance (alloc , InstanceManual ):
115
115
crn_url = sanitize_url (alloc .crn_url )
116
116
else :
117
+ if not alloc .allocations :
118
+ return str (item_hash ), None
117
119
crn_url = sanitize_url (alloc .allocations .node .url )
118
120
119
121
if not crn_url :
Original file line number Diff line number Diff line change 1
- from typing import TYPE_CHECKING
1
+ from typing import TYPE_CHECKING , Optional
2
2
3
3
import aiohttp
4
+ from aiohttp import ClientResponseError
4
5
from aleph_message .models import ItemHash
5
6
6
7
from aleph .sdk .conf import settings
@@ -40,15 +41,18 @@ async def get_nodes(self) -> SchedulerNodes:
40
41
41
42
return SchedulerNodes .model_validate (raw )
42
43
43
- async def get_allocation (self , vm_hash : ItemHash ) -> AllocationItem :
44
+ async def get_allocation (self , vm_hash : ItemHash ) -> Optional [ AllocationItem ] :
44
45
"""
45
46
Fetch allocation information for a given VM hash.
46
47
"""
47
48
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
Original file line number Diff line number Diff line change @@ -174,7 +174,9 @@ class AllocationItem(BaseModel):
174
174
175
175
class InstanceWithScheduler (BaseModel ):
176
176
source : Literal ["scheduler" ]
177
- allocations : AllocationItem # Case Scheduler
177
+ allocations : Optional [
178
+ AllocationItem
179
+ ] # Case Scheduler (None == allocation can't be find on scheduler)
178
180
179
181
180
182
class InstanceManual (BaseModel ):
You can’t perform that action at this time.
0 commit comments