Skip to content

delete from storage #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion code/backend/batch/utilities/helpers/AzureBlobStorageClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,21 @@ def delete_file(self, file_name):
blob_client = self.blob_service_client.get_blob_client(
container=self.container_name, blob=file_name
)
blob_client.delete_blob()
if blob_client.exists():
blob_client.delete_blob()

def delete_files(self, files):
"""
Deletes files from the Azure Blob Storage container.

Args:
files (list[str]): The names of the files to delete.

Returns:
None
"""
for filename, ids in files.items():
self.delete_file(filename)

def get_all_files(self):
# Get all files in the container from Azure Blob Storage
Expand Down
4 changes: 4 additions & 0 deletions code/backend/pages/03_Delete_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from batch.utilities.helpers.EnvHelper import EnvHelper
from batch.utilities.search.Search import Search
from batch.utilities.helpers.AzureBlobStorageClient import AzureBlobStorageClient

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
env_helper: EnvHelper = EnvHelper()
Expand Down Expand Up @@ -65,6 +66,9 @@
files_to_delete = search_handler.delete_files(
selected_files,
)
# Delete from Storage
blob_client = AzureBlobStorageClient()
blob_client.delete_files(selected_files)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that @liammoat is handling the blob delete event to delete the document from the search index under #893, do you think we should just do the blob delete from here, and let the function trigger handle the index delete?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will close this PR for now and wait for @liammoat changes to go in

if len(files_to_delete) > 0:
st.success("Deleted files: " + str(files_to_delete))

Expand Down
Loading