Skip to content

Commit

Permalink
Track direct downloads to reuse the STS export
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Nov 14, 2022
1 parent aa4519f commit 0c170c7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 24 deletions.
9 changes: 8 additions & 1 deletion client/src/components/Common/ExportRecordDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const props = defineProps({
},
});
const emit = defineEmits(["onReimport"]);
const emit = defineEmits(["onReimport", "onDownload"]);
const title = computed(() => (props.record.isReady ? `Exported` : `Export started`));
const elapsedTime = computed(() => formatDistanceToNow(parseISO(`${props.record.date}Z`), { addSuffix: true }));
Expand All @@ -39,6 +39,10 @@ const preparingMessage = computed(
function reimportObject() {
emit("onReimport", props.record);
}
function downloadObject() {
emit("onDownload", props.record);
}
</script>

<template>
Expand All @@ -60,6 +64,9 @@ function reimportObject() {
<p class="mt-3">
{{ readyMessage }}
</p>
<b-button v-if="props.record.canDownload" variant="primary" @click="downloadObject">
Download
</b-button>
<b-button v-if="props.record.canReimport" variant="primary" @click="reimportObject">
Reimport
</b-button>
Expand Down
17 changes: 14 additions & 3 deletions client/src/components/Common/models/exportRecordModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ export class ExportRecordModel {
return this._data.task_uuid;
}

// import_uri doesn't work for downloads
get canReimport() {
return this._data?.export_metadata?.result_data?.import_uri !== undefined;
return this.isReady && !!this._data?.export_metadata?.result_data?.target_uri;
}

get importLink() {
return this._data?.export_metadata?.result_data?.import_uri;
return this._data?.export_metadata?.result_data?.target_uri;
}

get isStsDownload() {
return !!this._data?.export_metadata?.result_data?.short_term_storage_request_id;
}

get stsDownloadId() {
return this._data?.export_metadata?.result_data?.short_term_storage_request_id;
}

get canDownload() {
return this.isReady && this.isStsDownload;
}
}
22 changes: 17 additions & 5 deletions client/src/components/History/Export/HistoryExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const service = new HistoryExportService();
const { isRunning: isExportTaskRunning, waitForTask } = useTaskMonitor();
const { hasWritable: hasWritableFileSources } = useFileSources();
const { isPreparing: isPreparingDownload, downloadHistory } = useShortTermStorage();
const { isPreparing: isPreparingDownload, downloadHistory, downloadObjectByRequestId } = useShortTermStorage();
const props = defineProps({
historyId: {
Expand Down Expand Up @@ -70,11 +70,22 @@ async function exportToFileSource(exportDirectory, fileName) {
}
async function prepareDownload() {
downloadHistory(props.historyId, { pollDelayInMs: 3000, exportParams: EXPORT_PARAMS });
// updateExports();
if (latestExportRecord.value?.isStsDownload && latestExportRecord.value.isUpToDate) {
console.debug("Existing STS download found");
downloadObjectByRequestId(latestExportRecord.value.stsDownloadId);
return;
}
await downloadHistory(props.historyId, { pollDelayInMs: 3000, exportParams: EXPORT_PARAMS });
updateExports();
}
function downloadFromRecord(record) {
if (record.isStsDownload) {
downloadObjectByRequestId(record.stsDownloadId);
}
}
function reimportHistoryFromRecord(record) {
function reimportFromRecord(record) {
return service.reimportHistoryFromRecord(record);
}
</script>
Expand Down Expand Up @@ -111,7 +122,8 @@ function reimportHistoryFromRecord(record) {
:record="latestExportRecord"
object-type="history"
class="mt-3"
@onReimport="reimportHistoryFromRecord" />
@onDownload="downloadFromRecord"
@onReimport="reimportFromRecord" />
<b-alert v-else-if="errorMessage" variant="danger" class="mt-3" show>
{{ errorMessage }}
</b-alert>
Expand Down
10 changes: 6 additions & 4 deletions client/src/composables/shortTermStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export function useShortTermStorage() {

const isPreparing = ref(false);

function downloadHistory(historyId, options = DEFAULT_OPTIONS) {
async function downloadHistory(historyId, options = DEFAULT_OPTIONS) {
return prepareObjectDownload(historyId, "histories", options);
}

function downloadWorkflowInvocation(invocationId, options = DEFAULT_OPTIONS) {
async function downloadWorkflowInvocation(invocationId, options = DEFAULT_OPTIONS) {
return prepareObjectDownload(invocationId, "invocations", options);
}

Expand All @@ -34,7 +34,7 @@ export function useShortTermStorage() {
window.location.assign(url);
}

function prepareObjectDownload(object_id, object_api, options = DEFAULT_OPTIONS) {
async function prepareObjectDownload(object_id, object_api, options = DEFAULT_OPTIONS) {
const finalOptions = Object.assign(DEFAULT_OPTIONS, options);
resetTimeout();
isPreparing.value = true;
Expand All @@ -46,7 +46,9 @@ export function useShortTermStorage() {
include_deleted: finalOptions.exportParams.includeDeleted,
include_hidden: finalOptions.exportParams.includeHidden,
};
axios.post(url, exportParams).then(handleInitialize).catch(handleError);

const response = await axios.post(url, exportParams).catch(handleError);
handleInitialize(response);
}

function handleInitialize(response) {
Expand Down
16 changes: 12 additions & 4 deletions lib/galaxy/managers/model_stores.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, Union

from galaxy import model
from galaxy.exceptions import RequestParameterInvalidException
Expand All @@ -20,6 +20,7 @@
ExportObjectType,
HistoryContentType,
WriteStoreToPayload,
ShortTermStoreExportPayload,
)
from galaxy.schema.tasks import (
BcoGenerationTaskParametersMixin,
Expand Down Expand Up @@ -86,6 +87,7 @@ def prepare_history_download(self, request: GenerateHistoryDownload):
short_term_storage_target.path
) as export_store:
export_store.export_history(history, include_hidden=include_hidden, include_deleted=include_deleted)
self.set_history_export_metadata(request)

def prepare_history_content_download(self, request: GenerateHistoryContentDownload):
model_store_format = request.model_store_format
Expand Down Expand Up @@ -177,16 +179,22 @@ def write_history_to(self, request: WriteHistoryTo):
)
self.set_history_export_metadata(request)

def set_history_export_metadata(self, request: WriteHistoryTo):
def set_history_export_metadata(self, request: Union[WriteHistoryTo, GenerateHistoryDownload]):
if request.export_association_id:
request_dict = request.dict()
request_payload = (
WriteStoreToPayload(**request_dict)
if isinstance(request, WriteHistoryTo)
else ShortTermStoreExportPayload(**request_dict)
)
export_metadata = ExportObjectMetadata(
request_data=ExportObjectRequestMetadata(
object_id=request.history_id,
object_type=ExportObjectType.HISTORY,
user_id=request.user.user_id,
payload=WriteStoreToPayload(**request.dict()),
payload=request_payload,
),
result_data=ExportObjectResultMetadata(import_uri=request.target_uri),
result_data=ExportObjectResultMetadata(**request_dict),
)
self._export_tracker.set_export_association_metadata(request.export_association_id, export_metadata)

Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,11 +1428,12 @@ class ExportObjectRequestMetadata(Model):
object_id: EncodedDatabaseIdField
object_type: ExportObjectType
user_id: Optional[EncodedDatabaseIdField]
payload: WriteStoreToPayload
payload: Union[WriteStoreToPayload, ShortTermStoreExportPayload]


class ExportObjectResultMetadata(Model):
import_uri: str
target_uri: Optional[str]
short_term_storage_request_id: Optional[str]


class ExportObjectMetadata(Model):
Expand Down
14 changes: 9 additions & 5 deletions lib/galaxy/webapps/galaxy/services/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,19 @@ def prepare_download(
history.name,
payload.model_store_format,
)
export_association = self.history_export_manager.create_export_association(history.id)
request = GenerateHistoryDownload(
history_id=history.id,
short_term_storage_request_id=short_term_storage_target.request_id,
user=trans.async_request_user,
export_association_id=export_association.id,
**payload.dict(),
)
result = prepare_history_download.delay(request=request)
return AsyncFile(storage_request_id=short_term_storage_target.request_id, task=async_task_summary(result))
task_summary = async_task_summary(result)
export_association.task_uuid = task_summary.id
trans.sa_session.flush()
return AsyncFile(storage_request_id=short_term_storage_target.request_id, task=task_summary)

def write_store(
self, trans: ProvidesHistoryContext, history_id: DecodedDatabaseIdField, payload: WriteStoreToPayload
Expand All @@ -358,11 +363,10 @@ def write_store(
**payload.dict(),
)
result = write_history_to.delay(request=request)
summary = async_task_summary(result)
# TODO: will this race?
export_association.task_uuid = summary.id
task_summary = async_task_summary(result)
export_association.task_uuid = task_summary.id
trans.sa_session.flush()
return summary
return task_summary

def update(
self,
Expand Down

0 comments on commit 0c170c7

Please sign in to comment.