Skip to content

Commit 96d4307

Browse files
authored
Requests costs to broker db (#201)
* pass request costs to broker db * fix types
1 parent 98df09a commit 96d4307

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cads_processing_api_service/auth.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,9 @@ def verify_if_disabled(disabled_reason: str | None, user_role: str | None) -> No
267267
return
268268

269269

270-
def verify_cost(request: dict[str, Any], adaptor_properties: dict[str, Any]) -> None:
270+
def verify_cost(
271+
request: dict[str, Any], adaptor_properties: dict[str, Any]
272+
) -> dict[str, float] | None:
271273
"""Verify if the cost of a process execution request is within the allowed limits.
272274
273275
Parameters
@@ -281,6 +283,11 @@ def verify_cost(request: dict[str, Any], adaptor_properties: dict[str, Any]) ->
281283
------
282284
exceptions.PermissionDenied
283285
Raised if the cost of the process execution request exceeds the allowed limits.
286+
287+
Returns
288+
-------
289+
dict[str, float] | None
290+
Request costs.
284291
"""
285292
costing_info = costing.compute_costing(request, adaptor_properties)
286293
max_costs_exceeded = costing_info.max_costs_exceeded
@@ -290,4 +297,4 @@ def verify_cost(request: dict[str, Any], adaptor_properties: dict[str, Any]) ->
290297
detail="Your request is too large, please reduce your selection.",
291298
)
292299
else:
293-
return
300+
return costing_info.costs

cads_processing_api_service/clients.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def post_process_execution(
231231
cads_adaptors.exceptions.InvalidRequest,
232232
) as exc:
233233
raise exceptions.InvalidRequest(detail=str(exc)) from exc
234-
auth.verify_cost(request_inputs, adaptor_properties)
234+
costs = auth.verify_cost(request_inputs, adaptor_properties)
235235
licences = adaptor.get_licences(request_inputs)
236236
auth.validate_licences(accepted_licences, licences)
237237
job_id = str(uuid.uuid4())
@@ -251,6 +251,7 @@ def post_process_execution(
251251
process_id=process_id,
252252
portal=dataset.portal,
253253
qos_tags=dataset.qos_tags,
254+
metadata={"costs": costs},
254255
**job_kwargs,
255256
)
256257
dataset_messages = [

0 commit comments

Comments
 (0)