Skip to content

Update/operation tmp dirs #81

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

Merged
merged 6 commits into from
Apr 14, 2025
Merged

Update/operation tmp dirs #81

merged 6 commits into from
Apr 14, 2025

Conversation

LTDakin
Copy link
Contributor

@LTDakin LTDakin commented Apr 8, 2025

Adds a temp attribute to the Data Operation base class that is cleaned up with a destructor when the class is garbage collected. Creates a dir unique to that operation so that any files created are removed at the end of an operation.

Updated all operations to use this. It's more of a safety net since it only catches affineremap's extra files for now but its good security to make sure we're not leaving any leftover files after an operation.

@LTDakin LTDakin requested review from jnation3406 and capetillo April 8, 2025 22:39

class BaseDataOperation(ABC):

def __init__(self, input_data: dict = None):
""" The data inputs are passed in in the format described from the wizard_description """
self.input_data = self._normalize_input_data(input_data)
self.cache_key = self.generate_cache_key()
self.temp = settings.TEMP_FITS_DIR # default fallback

try:
Copy link
Contributor

@jnation3406 jnation3406 Apr 11, 2025

Choose a reason for hiding this comment

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

Don't put this in the init for the data operation. There are several places in the server where we instantiate a data operation just to get its cache_key from an input set to check if its in the cache, where we never intend to do the operation. This code should just wrap the operate method to create and destroy the temp dir I think.

@LTDakin LTDakin requested review from jnation3406 April 14, 2025 18:00
Copy link
Contributor

@jnation3406 jnation3406 left a comment

Choose a reason for hiding this comment

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

looks good

tmp_hash_path = os.path.join(self.temp, self.cache_key)
# If tmp dir already exists, append a random hash to avoid collision
if os.path.exists(tmp_hash_path):
tmp_hash_path = os.path.join(tmp_hash_path, hashlib.sha256(os.urandom(8)).hexdigest())
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be possible since its just the cache_key which should ensure we are only operating on it once... But I guess its fine to have as extra protection.

Copy link
Contributor Author

@LTDakin LTDakin Apr 14, 2025

Choose a reason for hiding this comment

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

I was thinking if someone ran the same operation on another computer at the same time: ex. Median on the same two images. Thought it might be more possible in a classroom setting. Is a very unique edge case though

@LTDakin LTDakin merged commit 77039e2 into main Apr 14, 2025
3 checks passed
@LTDakin LTDakin deleted the update/operation-tmp-dirs branch April 14, 2025 19:02
@LTDakin LTDakin linked an issue Apr 15, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

align_fits library creates temp files that remain after operation
2 participants