Skip to content

Commit

Permalink
Add method to purge a list of datasets from store
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Feb 7, 2023
1 parent 1bfdbf8 commit 5ef066f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
22 changes: 21 additions & 1 deletion lib/galaxy/managers/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
secured,
users,
)
from galaxy.schema.tasks import ComputeDatasetHashTaskRequest
from galaxy.schema.tasks import (
ComputeDatasetHashTaskRequest,
PurgeDatasetsTaskRequest,
)
from galaxy.structured_app import MinimalManagerApp
from galaxy.util.hash_util import memory_bound_hexdigest

Expand Down Expand Up @@ -85,6 +88,23 @@ def purge(self, dataset, flush=True):
self.session().flush()
return dataset

def purge_datasets(self, request: PurgeDatasetsTaskRequest):
"""
Caution: any additional security checks must be done before executing this action.
Completely removes a set of object_store/files associated with the datasets from storage and marks them as purged.
They might not be removed if there are still un-purged associations to the dataset.
"""
self.error_unless_dataset_purge_allowed()
with self.session().begin():
for dataset_id in request.dataset_ids:
dataset: model.Dataset = self.session().query(model.Dataset).get(dataset_id)
if dataset.user_can_purge:
try:
dataset.full_delete()
except Exception:
log.exception(f"Unable to purge dataset ({dataset.id})")

# TODO: this may be more conv. somewhere else
# TODO: how to allow admin bypass?
def error_unless_dataset_purge_allowed(self, msg=None):
Expand Down
9 changes: 8 additions & 1 deletion lib/galaxy/schema/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from typing import Optional
from typing import (
List,
Optional,
)
from uuid import UUID

from pydantic import (
Expand Down Expand Up @@ -116,3 +119,7 @@ class ComputeDatasetHashTaskRequest(BaseModel):
extra_files_path: Optional[str]
hash_function: HashFunctionNameEnum
user: Optional[RequestUser] # access checks should be done pre-celery so this is optional


class PurgeDatasetsTaskRequest(BaseModel):
dataset_ids: List[int]

0 comments on commit 5ef066f

Please sign in to comment.