Skip to content

Commit

Permalink
auto-expire export zips
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-wahl committed Sep 6, 2024
1 parent 53f76dc commit f944c71
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions processors/conversion/export_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""
import shutil
import json
import datetime

from backend.lib.processor import BasicProcessor
from common.lib.dataset import DataSet
from common.lib.exceptions import ProcessorException, DataSetException
from common.lib.exceptions import DataSetException

__author__ = "Dale Wahl"
__credits__ = ["Dale Wahl"]
Expand All @@ -22,7 +23,7 @@ class ExportDatasets(BasicProcessor):
type = "export-datasets" # job type ID
category = "Conversion" # category
title = "Export Dataset and All Analyses" # title displayed in UI
description = "Creates a ZIP file containing the dataset and all analyses to be archived and uploaded to a 4CAT instance in the future" # description displayed in UI
description = "Creates a ZIP file containing the dataset and all analyses to be archived and uploaded to a 4CAT instance in the future. Automatically expires after 1 day, after which you must run again." # description displayed in UI
extension = "zip" # extension of result file, used internally and in UI

@classmethod
Expand Down Expand Up @@ -96,5 +97,10 @@ def process(self):
self.dataset.log(f"Failed to export datasets: {failed_exports}")
shutil.copy(self.dataset.get_log_path(), results_path.joinpath("export.log"))

# set expiration date
# these datasets can be very large and are just copies of the existing datasets, so we don't need to keep them around for long
# TODO: convince people to stop using hyphens in python variables and file names...
self.dataset.__setattr__("expires-after", (datetime.datetime.now() + datetime.timedelta(days=1)).timestamp())

# done!
self.write_archive_and_finish(results_path, len(exported_datasets))

0 comments on commit f944c71

Please sign in to comment.