Skip to content

Commit 3ce69e1

Browse files
committed
Try handling unknown error separately
1 parent 3e536ce commit 3ce69e1

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

cerulean_cloud/cloud_run_orchestrator/clients.py

+14-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Clients for other cloud run functions"""
22
import asyncio
33
import json
4-
import logging
54
import os
65
import zipfile
76
from base64 import b64encode
@@ -74,65 +73,38 @@ async def get_base_tile_inference(
7473
self, tile: morecantile.Tile, semaphore: asyncio.Semaphore, rescale=(0, 255)
7574
) -> InferenceResultStack:
7675
"""fetch inference for base tiles"""
77-
logging.basicConfig(level=logging.INFO)
7876
async with semaphore:
79-
logging.info("Fetching base tile.")
8077
img_array = await self.titiler_client.get_base_tile(
8178
sceneid=self.sceneid, tile=tile, scale=self.scale, rescale=rescale
8279
)
8380

84-
logging.info("Reshaping image array.")
8581
img_array = reshape_as_raster(img_array)
8682

87-
logging.info("Getting tile bounds.")
8883
bounds = list(TMS.bounds(tile))
8984

90-
logging.info("Reading auxiliary datasets.")
9185
with self.aux_datasets.open() as src:
9286
window = rasterio.windows.from_bounds(*bounds, transform=src.transform)
9387
height, width = img_array.shape[1:]
9488
aux_ds = src.read(window=window, out_shape=(height, width))
9589

96-
logging.info("Concatenating image arrays.")
9790
img_array = np.concatenate([img_array[0:1, :, :], aux_ds], axis=0)
9891

99-
logging.info("Encoding image to base64.")
10092
encoded = img_array_to_b64_image(img_array)
10193

102-
logging.info("Preparing payload for prediction.")
10394
inf_stack = [InferenceInput(image=encoded, bounds=TMS.bounds(tile))]
104-
105-
logging.info("Preparing payload for prediction.")
106-
107-
# Log the length of inf_stack
108-
logging.info(f"Length of inf_stack: {len(inf_stack)}")
109-
110-
# Log a sample from inf_stack
111-
logging.info(
112-
f"Sample from inf_stack: {inf_stack[:1]}"
113-
) # adjust the slice as needed
114-
115-
# Log inf_parms
116-
logging.info(f"inf_parms: {self.inference_parms}")
117-
118-
# Create and log the entire payload
11995
payload = PredictPayload(
12096
inf_stack=inf_stack, inf_parms=self.inference_parms
12197
)
122-
logging.info(f"Complete PredictPayload: {payload.dict()}")
123-
124-
logging.info(f"Sending request to {self.url + '/predict'}.")
12598
res = await self.client.post(
12699
self.url + "/predict", json=payload.dict(), timeout=None
127100
)
128-
129-
logging.info("Processing response.")
130-
print(f"DEBUG len(inf_stack): {len(inf_stack)}")
131-
print(f"DEBUG inf_stack[:1]: {inf_stack[:1]}")
132-
print(f"DEBUG self.url + '/predict': {self.url + '/predict'}")
133-
print(f"DEBUG payload.dict(): {payload.dict()}")
134-
print(f"DEBUG res: {res}")
135-
return InferenceResultStack(**res.json())
101+
if res.status_code == 200:
102+
return InferenceResultStack(**res.json())
103+
else:
104+
print(f"XXX Received unexpected status code: {res.status_code}")
105+
print(f"XXX HTTP content: {res.content}")
106+
print(f"XXX Issue was found in: {self.sceneid}")
107+
return InferenceResultStack([])
136108

137109
async def get_offset_tile_inference(
138110
self, bounds: List[float], semaphore: asyncio.Semaphore, rescale=(0, 255)
@@ -161,7 +133,13 @@ async def get_offset_tile_inference(
161133
res = await self.client.post(
162134
self.url + "/predict", json=payload.dict(), timeout=None
163135
)
164-
return InferenceResultStack(**res.json())
136+
if res.status_code == 200:
137+
return InferenceResultStack(**res.json())
138+
else:
139+
print(f"XXX Received unexpected status code: {res.status_code}")
140+
print(f"XXX HTTP content: {res.content}")
141+
print(f"XXX Issue was found in: {self.sceneid}")
142+
return InferenceResultStack([])
165143

166144

167145
def get_scene_date_month(scene_id: str) -> str:

cerulean_cloud/cloud_run_orchestrator/handler.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,10 @@ def flatten_feature_list(
221221
"""flatten a feature list coming from inference"""
222222
flat_list: List[geojson.Feature] = []
223223
for r in stack_list:
224-
for i in r.stack:
225-
for f in i.features:
226-
flat_list.append(f)
224+
if r.get("stack"):
225+
for i in r.stack:
226+
for f in i.features:
227+
flat_list.append(f)
227228
return flat_list
228229

229230

@@ -350,7 +351,7 @@ async def _orchestrate(
350351
)
351352
for base_tile in base_tiles
352353
],
353-
return_exceptions=False,
354+
return_exceptions=True,
354355
)
355356

356357
logging.info("Inference on offset tiles!")
@@ -364,7 +365,7 @@ async def _orchestrate(
364365
)
365366
for offset_tile_bounds in offset_tiles_bounds
366367
],
367-
return_exceptions=False,
368+
return_exceptions=True,
368369
)
369370

370371
if base_tiles_inference[0].stack[0].dict().get("classes"):

0 commit comments

Comments
 (0)