Skip to content

Commit

Permalink
chore: use save image task output to update orc function
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <[email protected]>
  • Loading branch information
ThibaultFy committed Feb 8, 2024
1 parent 99f551e commit 759a810
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions backend/substrapp/tasks/tasks_save_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,13 @@ def get_task_info(self, args: tuple, kwargs: dict) -> tuple[str, str]:
return function.key, channel_name

# Celery does not provide unpacked arguments, we are doing it in `get_task_info`
def on_success(self, retval: dict[str, Any], task_id: str, args: tuple, kwargs: dict[str, Any]) -> None:
function_key, channel_name = self.get_task_info(args, kwargs)

# needed because the name is not an optional parameter
api_function = ApiFunction.objects.get(key=function_key)

function_image = FunctionImage.objects.get(function=api_function)

orc_function = {
"key": str(function_key),
# TODO find a way to propagate the name or make it optional at update
"name": api_function.name,
"image": {
"checksum": function_image.checksum,
# TODO check url
"storage_address": settings.DEFAULT_DOMAIN + reverse("api:function-image", args=[function_key]),
},
}
def on_success(self, retval: tuple[str, str], task_id: str, args: tuple, kwargs: dict[str, Any]) -> None:
orc_update_function_param, channel_name = retval

with get_orchestrator_client(channel_name) as client:
# TODO atomiticy
client.update_function(orc_function)
client.update_function(orc_update_function_param)
client.update_function_status(
function_key=function_key, action=orchestrator.function_pb2.FUNCTION_ACTION_READY
function_key=orc_update_function_param["key"], action=orchestrator.function_pb2.FUNCTION_ACTION_READY
)


Expand Down Expand Up @@ -122,4 +105,15 @@ def save_image_task(task: SaveImageTask, function_serialized: str, channel_name:

logger.info("Serialized image saved")

return function_serialized, channel_name
orc_update_function_param = {
"key": str(api_function.key),
# TODO find a way to propagate the name or make it optional at update
"name": api_function.name,
"image": {
"checksum": api_function.image_checksum,
# TODO check url
"storage_address": api_function.image_address,
},
}

return orc_update_function_param, channel_name

0 comments on commit 759a810

Please sign in to comment.