@@ -254,6 +254,21 @@ async def prepare_port(self,state,target,key):
254254 value .update (route_key = key ,job = state ['native' ]['job' ],source = 'resident collision terrain' ,
255255 policy = REGIONAL_POLICY ,probe_position = current ,mapped_land_checked = guard is not None )
256256 return value
257+ async def terrain_region (self , centre , extent ):
258+ """Try a smaller verified region when the baseline provider is offline."""
259+ for width in (extent , 6000 ) if extent > 6000 else (extent ,):
260+ job = await self .rpc ('/terrain/jobs' ,dict (latitude = centre [1 ],longitude = centre [0 ],
261+ width_m = width ,height_m = width ,samples = 257 ,source_policy = 'auto' ),20 )
262+ end = time .monotonic ()+ 620
263+ while job ['status' ] in ('queued' ,'running' ) and time .monotonic ()< end :
264+ await asyncio .sleep (2 );job = await self .rpc ('/terrain/jobs/' + job ['id' ])
265+ if job ['status' ]== 'ready' :return job
266+ if width == 6000 or job ['status' ]!= 'failed' :break
267+ try :
268+ sources = await self .rpc ('/terrain/jobs/' + job ['id' ]+ '/files/source-providers.json' )
269+ except Exception :break
270+ if (sources .get ('baseline_status' ) or {}).get ('status' )!= 'unavailable' :break
271+ raise RuntimeError ('regional_terrain_unavailable' )
257272 async def prepare (self ,state ,target ,key ,nearest = None ,needed = True ):
258273 from posim_terrain .canal_override import in_region
259274 canal = in_region (state ['position' ])
@@ -276,11 +291,7 @@ async def prepare(self,state,target,key,nearest=None,needed=True):
276291 centre = list (GEO .fwd (* pos ,heading ,min (6000. ,nearest [0 ]- 6000. ))[:2 ])
277292 extent = 4000 if canal else 20000
278293 if self .before_prepare is not None :await self .before_prepare ()
279- job = await self .rpc ('/terrain/jobs' ,dict (latitude = centre [1 ],longitude = centre [0 ],width_m = extent ,height_m = extent ,samples = 257 ,source_policy = 'auto' ),20 )
280- end = time .monotonic ()+ 620
281- while job ['status' ] in ('queued' ,'running' ) and time .monotonic ()< end :
282- await asyncio .sleep (2 );job = await self .rpc ('/terrain/jobs/' + job ['id' ])
283- if job ['status' ]!= 'ready' :raise RuntimeError ('regional_terrain_unavailable' )
294+ job = await self .terrain_region (centre ,extent )
284295 grid = await self .rpc ('/terrain/jobs/' + job ['id' ]+ '/files/terrain.json' ,timeout = 20 )
285296 guard = None
286297 if not canal :
0 commit comments