Skip to content

Commit 895bb88

Browse files
committed
fix: updated error handling for upscaling tasks
1 parent 1c0270d commit 895bb88

File tree

4 files changed

+164
-66
lines changed

4 files changed

+164
-66
lines changed

app/services/processing.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,48 @@ async def create_processing_job(
3939
user = get_current_user_id(token)
4040
logger.info(f"Creating processing job for {user} with summary: {request}")
4141

42-
platform = get_processing_platform(request.label)
42+
try:
43+
platform = get_processing_platform(request.label)
44+
45+
job_id = await platform.execute_job(
46+
user_token=token,
47+
title=request.title,
48+
details=request.service,
49+
parameters=request.parameters,
50+
format=request.format,
51+
)
4352

44-
job_id = await platform.execute_job(
45-
user_token=token,
46-
title=request.title,
47-
details=request.service,
48-
parameters=request.parameters,
49-
format=request.format,
50-
)
53+
record = ProcessingJobRecord(
54+
title=request.title,
55+
label=request.label,
56+
status=(
57+
ProcessingStatusEnum.CREATED if job_id else ProcessingStatusEnum.FAILED
58+
),
59+
user_id=user,
60+
platform_job_id=job_id,
61+
parameters=json.dumps(request.parameters),
62+
service=request.service.model_dump_json(),
63+
upscaling_task_id=upscaling_task_id,
64+
)
65+
66+
except Exception as e:
67+
logger.error(f"Error creating processing job: {e}")
68+
69+
if upscaling_task_id:
70+
# Do create the record in case of upscaling task to mark it as failed
71+
record = ProcessingJobRecord(
72+
title=request.title,
73+
label=request.label,
74+
status=ProcessingStatusEnum.FAILED,
75+
user_id=user,
76+
platform_job_id=None,
77+
parameters=json.dumps(request.parameters),
78+
service=request.service.model_dump_json(),
79+
upscaling_task_id=upscaling_task_id,
80+
)
81+
else:
82+
raise e
5183

52-
record = ProcessingJobRecord(
53-
title=request.title,
54-
label=request.label,
55-
status=ProcessingStatusEnum.CREATED if job_id else ProcessingStatusEnum.FAILED,
56-
user_id=user,
57-
platform_job_id=job_id,
58-
parameters=json.dumps(request.parameters),
59-
service=request.service.model_dump_json(),
60-
upscaling_task_id=upscaling_task_id,
61-
)
6284
record = save_job_to_db(database, record)
6385
return ProcessingJobSummary(
6486
id=record.id,

guides/execution_example.ipynb

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 26,
14+
"execution_count": 1,
1515
"id": "d99f5fbc",
1616
"metadata": {},
1717
"outputs": [],
@@ -39,7 +39,7 @@
3939
},
4040
{
4141
"cell_type": "code",
42-
"execution_count": 27,
42+
"execution_count": 2,
4343
"id": "e8c7ffff-4d0a-4e0c-bc98-44f90316f20c",
4444
"metadata": {},
4545
"outputs": [],
@@ -62,7 +62,7 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 28,
65+
"execution_count": 3,
6666
"id": "4139eacf-03a4-4815-83d2-b2ee04e90331",
6767
"metadata": {},
6868
"outputs": [],
@@ -92,7 +92,7 @@
9292
},
9393
{
9494
"cell_type": "code",
95-
"execution_count": 29,
95+
"execution_count": 4,
9696
"id": "f95065a9",
9797
"metadata": {},
9898
"outputs": [],
@@ -102,7 +102,7 @@
102102
},
103103
{
104104
"cell_type": "code",
105-
"execution_count": 30,
105+
"execution_count": 5,
106106
"id": "251a343f",
107107
"metadata": {},
108108
"outputs": [],
@@ -113,7 +113,7 @@
113113
},
114114
{
115115
"cell_type": "code",
116-
"execution_count": 31,
116+
"execution_count": 6,
117117
"id": "c83aa9d5",
118118
"metadata": {},
119119
"outputs": [],
@@ -136,7 +136,7 @@
136136
},
137137
{
138138
"cell_type": "code",
139-
"execution_count": 32,
139+
"execution_count": 7,
140140
"id": "53d0800c-a6b3-4a64-a7a2-f27689adc7d7",
141141
"metadata": {},
142142
"outputs": [],
@@ -148,22 +148,22 @@
148148
},
149149
{
150150
"cell_type": "code",
151-
"execution_count": 33,
151+
"execution_count": 8,
152152
"id": "6de8d686",
153153
"metadata": {},
154154
"outputs": [
155155
{
156156
"data": {
157157
"application/vnd.jupyter.widget-view+json": {
158-
"model_id": "fe81d39a308d4b7582afb6fb758557fe",
158+
"model_id": "4fe3833455684ef3ad97a1e52e248de0",
159159
"version_major": 2,
160160
"version_minor": 0
161161
},
162162
"text/plain": [
163163
"Map(center=[47.985, 16.378000000000004], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_t…"
164164
]
165165
},
166-
"execution_count": 33,
166+
"execution_count": 8,
167167
"metadata": {},
168168
"output_type": "execute_result"
169169
}
@@ -191,7 +191,7 @@
191191
},
192192
{
193193
"cell_type": "code",
194-
"execution_count": 34,
194+
"execution_count": 9,
195195
"id": "47c7fe82-b611-404c-9cb8-204497dbec57",
196196
"metadata": {},
197197
"outputs": [],
@@ -202,7 +202,7 @@
202202
},
203203
{
204204
"cell_type": "code",
205-
"execution_count": 35,
205+
"execution_count": 10,
206206
"id": "b5ee27f5-9e69-4557-ba83-ec7cb74aa874",
207207
"metadata": {},
208208
"outputs": [],
@@ -263,15 +263,29 @@
263263
},
264264
{
265265
"cell_type": "code",
266-
"execution_count": 48,
266+
"execution_count": 11,
267267
"id": "c5ca3fdd-7559-4fc7-8318-61b5dc59475f",
268268
"metadata": {},
269269
"outputs": [
270270
{
271271
"name": "stdout",
272272
"output_type": "stream",
273273
"text": [
274-
"{'id': 134, 'title': 'PV Farm Detection', 'label': 'openeo', 'status': 'created', 'service': {'endpoint': 'https://openeofed.dataspace.copernicus.eu', 'application': 'https://raw.githubusercontent.com/ESA-APEx/apex_algorithms/refs/heads/main/algorithm_catalog/eurac/eurac_pv_farm_detection/openeo_udp/eurac_pv_farm_detection.json'}, 'parameters': {'spatial_extent': {'west': 16.342, 'south': 47.962, 'east': 16.414, 'north': 48.008}, 'temporal_extent': ['2023-05-01', '2023-09-30']}}\n"
274+
"Open this URL in your browser: https://auth.dev.apex.esa.int/realms/apex/protocol/openid-connect/auth?response_type=code&client_id=apex-dispatcher-api-dev&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallback&state=UHVmNmG43imicvDFxGrvj70H5JAXQ8\n"
275+
]
276+
},
277+
{
278+
"name": "stdin",
279+
"output_type": "stream",
280+
"text": [
281+
"Paste the redirect URL here: http://localhost:8000/callback?state=UHVmNmG43imicvDFxGrvj70H5JAXQ8&session_state=6b99a56f-734f-4c38-b907-085815435e0b&iss=https%3A%2F%2Fauth.dev.apex.esa.int%2Frealms%2Fapex&code=c62e2916-9ec0-452d-acba-38a0e0705bc3.6b99a56f-734f-4c38-b907-085815435e0b.c2e791df-00a5-4981-b8af-b014848a2b73\n"
282+
]
283+
},
284+
{
285+
"name": "stdout",
286+
"output_type": "stream",
287+
"text": [
288+
"{'id': 148, 'title': 'PV Farm Detection', 'label': 'openeo', 'status': 'created', 'service': {'endpoint': 'https://openeofed.dataspace.copernicus.eu', 'application': 'https://raw.githubusercontent.com/ESA-APEx/apex_algorithms/refs/heads/main/algorithm_catalog/eurac/eurac_pv_farm_detection/openeo_udp/eurac_pv_farm_detection.json'}, 'parameters': {'spatial_extent': {'west': 16.342, 'south': 47.962, 'east': 16.414, 'north': 48.008}, 'temporal_extent': ['2023-05-01', '2023-09-30']}}\n"
275289
]
276290
}
277291
],
@@ -311,7 +325,7 @@
311325
},
312326
{
313327
"cell_type": "code",
314-
"execution_count": 49,
328+
"execution_count": 12,
315329
"id": "02e5c413-d110-4110-be59-c86e5226edc5",
316330
"metadata": {},
317331
"outputs": [],
@@ -354,14 +368,14 @@
354368
},
355369
{
356370
"cell_type": "code",
357-
"execution_count": 50,
371+
"execution_count": 13,
358372
"id": "ac428293-7cd4-49a8-9bfa-4e0dc8f4d2cc",
359373
"metadata": {},
360374
"outputs": [
361375
{
362376
"data": {
363377
"application/vnd.jupyter.widget-view+json": {
364-
"model_id": "0341e40c72df455f8bf0a98becc8a928",
378+
"model_id": "3780c8a4fbb248f4a4fb6f9f05e9929c",
365379
"version_major": 2,
366380
"version_minor": 0
367381
},
@@ -448,6 +462,14 @@
448462
"# Run the websocket listener in the notebook\n",
449463
"await listen_for_updates()"
450464
]
465+
},
466+
{
467+
"cell_type": "code",
468+
"execution_count": null,
469+
"id": "b8d57f37-8c56-4f22-8803-425e8e1128aa",
470+
"metadata": {},
471+
"outputs": [],
472+
"source": []
451473
}
452474
],
453475
"metadata": {

0 commit comments

Comments
 (0)