From 8b938232a060dc2a3d3c7612210688f26ee0ac3f Mon Sep 17 00:00:00 2001 From: Arseny Boykov <36469655+Bobronium@users.noreply.github.com> Date: Mon, 2 Sep 2024 12:42:52 +0200 Subject: [PATCH] [Exchange Oracle] Delete cloud storages after projects have been deleted --- .../src/handlers/escrow_cleanup.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/examples/cvat/exchange-oracle/src/handlers/escrow_cleanup.py b/packages/examples/cvat/exchange-oracle/src/handlers/escrow_cleanup.py index d7fc197ff6..96dee4149d 100644 --- a/packages/examples/cvat/exchange-oracle/src/handlers/escrow_cleanup.py +++ b/packages/examples/cvat/exchange-oracle/src/handlers/escrow_cleanup.py @@ -19,20 +19,17 @@ def _cleanup_cvat(projects: list[Project]) -> None: - deleted_cloud_storage_ids = set() + cloud_storage_ids_to_delete = set() # probably will allways have one element for project in projects: - if ( - project.cvat_cloudstorage_id is not None - and project.cvat_cloudstorage_id not in deleted_cloud_storage_ids - ): - with contextlib.suppress(NotFoundException): - # probably will allways call this just once - cvat_api.delete_cloudstorage(project.cvat_cloudstorage_id) - deleted_cloud_storage_ids.add(project.cvat_cloudstorage_id) + cloud_storage_ids_to_delete.add(project.cvat_cloudstorage_id) if project.cvat_id is not None: with contextlib.suppress(NotFoundException): cvat_api.delete_project(project.cvat_id) + for cloud_storage_id in cloud_storage_ids_to_delete: + with contextlib.suppress(NotFoundException): + cvat_api.delete_cloudstorage(cloud_storage_id) + def _cleanup_storage(escrow_address: str, chain_id: int) -> None: storage_client = cloud_service.make_client(BucketAccessInfo.parse_obj(Config.storage_config))