Skip to content

Commit f796927

Browse files
committed
Return async task result
1 parent cc6a708 commit f796927

6 files changed

Lines changed: 68 additions & 24 deletions

File tree

client/src/api/schema/schema.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,6 +7463,11 @@ export interface components {
74637463
* @description Whether this resource is currently publicly available to all users.
74647464
*/
74657465
published: boolean;
7466+
/**
7467+
* Purge Task
7468+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
7469+
*/
7470+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
74667471
/**
74677472
* Purged
74687473
* @description Whether this item has been permanently removed.
@@ -7586,6 +7591,11 @@ export interface components {
75867591
* @description Whether this resource is currently publicly available to all users.
75877592
*/
75887593
published: boolean;
7594+
/**
7595+
* Purge Task
7596+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
7597+
*/
7598+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
75897599
/**
75907600
* Purged
75917601
* @description Whether this item has been permanently removed.
@@ -9974,6 +9984,11 @@ export interface components {
99749984
* @description Whether this resource is currently publicly available to all users.
99759985
*/
99769986
published?: boolean | null;
9987+
/**
9988+
* Purge Task
9989+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
9990+
*/
9991+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
99779992
/**
99789993
* Purged
99799994
* @description Whether this item has been permanently removed.
@@ -10213,6 +10228,11 @@ export interface components {
1021310228
* @description Whether this resource is currently publicly available to all users.
1021410229
*/
1021510230
published?: boolean | null;
10231+
/**
10232+
* Purge Task
10233+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
10234+
*/
10235+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
1021610236
/**
1021710237
* Purged
1021810238
* @description Whether this item has been permanently removed.
@@ -15492,6 +15512,11 @@ export interface components {
1549215512
* @description Whether this resource is currently publicly available to all users.
1549315513
*/
1549415514
published: boolean;
15515+
/**
15516+
* Purge Task
15517+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
15518+
*/
15519+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
1549515520
/**
1549615521
* Purged
1549715522
* @description Whether this item has been permanently removed.
@@ -15613,6 +15638,11 @@ export interface components {
1561315638
* @description Whether this resource is currently publicly available to all users.
1561415639
*/
1561515640
published: boolean;
15641+
/**
15642+
* Purge Task
15643+
* @description Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.
15644+
*/
15645+
purge_task?: components["schemas"]["AsyncTaskResultSummary"] | null;
1561615646
/**
1561715647
* Purged
1561815648
* @description Whether this item has been permanently removed.

lib/galaxy/celery/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def purge_datasets(
121121
dataset_manager.purge_datasets(request)
122122

123123

124-
@galaxy_task(ignore_result=True, action="purge all datasets in a history")
124+
@galaxy_task(action="purge all datasets in a history")
125125
def purge_history_datasets(
126126
sa_session: galaxy_scoped_session,
127127
dataset_manager: DatasetManager,

lib/galaxy/managers/histories.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,16 @@ def purge(self, item, flush=True, **kwargs):
298298

299299
request = PurgeHistoryDatasetsTaskRequest(history_id=item.id)
300300
user = item.user
301-
purge_history_datasets.delay(request=request, task_user_id=user.id if user else None)
301+
result = purge_history_datasets.delay(request=request, task_user_id=user.id if user else None)
302302
else:
303+
result = None
303304
for hda in item.datasets:
304305
if not hda.purged:
305306
self.hda_manager.purge(hda, flush=True, **kwargs)
306307

307308
# Now mark the history as purged
308309
super().purge(item, flush=flush, **kwargs)
310+
return result
309311

310312
# .... current
311313
# TODO: make something to bypass the anon user + current history permissions issue

lib/galaxy/schema/schema.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,11 @@ class HistorySummary(Model, WithModelClass):
14351435
tags: TagCollection
14361436
update_time: datetime = UpdateTimeField
14371437
preferred_object_store_id: Optional[str] = PreferredObjectStoreIdField
1438+
purge_task: Optional["AsyncTaskResultSummary"] = Field(
1439+
None,
1440+
title="Purge Task",
1441+
description="Summary of the async task purging datasets in this history. Only present when purge is performed via a background task.",
1442+
)
14381443

14391444

14401445
class HistoryActiveContentCounts(Model):
@@ -3997,6 +4002,13 @@ class AsyncTaskResultSummary(Model):
39974002
)
39984003

39994004

4005+
HistorySummary.model_rebuild()
4006+
HistoryDetailed.model_rebuild()
4007+
CustomHistoryView.model_rebuild()
4008+
ArchivedHistorySummary.model_rebuild()
4009+
ArchivedHistoryDetailed.model_rebuild()
4010+
CustomArchivedHistoryView.model_rebuild()
4011+
40004012
ToolRequestIdField = Field(title="ID", description="Encoded ID of the role")
40014013

40024014

lib/galaxy/webapps/galaxy/services/histories.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,14 @@ def delete(
454454
"""
455455
history = self.manager.get_mutable(history_id, trans.user, current_history=trans.history)
456456
if purge:
457-
self.manager.purge(history)
457+
result = self.manager.purge(history)
458458
else:
459+
result = None
459460
self.manager.delete(history)
460-
return self._serialize_history(trans, history, serialization_params)
461+
rval = self._serialize_history(trans, history, serialization_params)
462+
if result is not None:
463+
rval["purge_task"] = async_task_summary(result)
464+
return rval
461465

462466
def undelete(
463467
self,

test/integration/test_purge_datasets.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
Optional,
55
)
66

7-
from galaxy_test.base.populators import (
8-
DatasetPopulator,
9-
wait_on,
10-
)
7+
from galaxy_test.base.populators import DatasetPopulator
118
from galaxy_test.driver import integration_util
129

1310

@@ -95,31 +92,30 @@ def test_purge_history_removes_underlying_datasets_from_disk(self):
9592
# Purge the entire history
9693
purge_response = self._delete(f"histories/{self.test_history_id}", data={"purge": True}, json=True)
9794
self._assert_status_code_is_ok(purge_response)
95+
purge_result = purge_response.json()
9896

9997
# Verify history is purged
100-
history_response = self._get(f"histories/{self.test_history_id}").json()
101-
assert history_response["purged"]
102-
assert history_response["deleted"]
98+
assert purge_result["purged"]
99+
assert purge_result["deleted"]
100+
101+
# Verify the response contains a purge_task with an id
102+
assert "purge_task" in purge_result
103+
purge_task = purge_result["purge_task"]
104+
assert "id" in purge_task
105+
purge_task_id = purge_task["id"]
106+
107+
# Wait for the celery task to complete via the tasks API
108+
self.dataset_populator.wait_on_task_id(purge_task_id)
103109

104-
# Verify HDAs are marked as purged
110+
# After task completion, HDAs should be purged and files deleted
105111
self.dataset_populator.wait_for_purge(self.test_history_id, hda1_id)
106112
self.dataset_populator.wait_for_purge(self.test_history_id, hda2_id)
107-
108-
# Wait for underlying dataset files to be removed from disk.
109-
# With batched history purging, HDAs are marked purged synchronously
110-
# but the actual file deletion happens via a batched celery task.
111-
self._wait_for_file_deleted(dataset_file1)
112-
self._wait_for_file_deleted(dataset_file2)
113+
assert not self._file_exists_on_disk(dataset_file1)
114+
assert not self._file_exists_on_disk(dataset_file2)
113115

114116
def _get_underlying_dataset_on_disk(self, hda_id: str) -> Optional[str]:
115117
detailed_response = self._get(f"datasets/{hda_id}", admin=True).json()
116118
return detailed_response.get("file_name")
117119

118120
def _file_exists_on_disk(self, filename: Optional[str]) -> bool:
119121
return os.path.isfile(filename) if filename else False
120-
121-
def _wait_for_file_deleted(self, filename: Optional[str], timeout: int = 10):
122-
def _check():
123-
return True if not self._file_exists_on_disk(filename) else None
124-
125-
wait_on(_check, f"file {filename} to be deleted", timeout=timeout)

0 commit comments

Comments
 (0)