Skip to content
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

Fix bugs related to the parent folder of a plugin instance's output dir #574

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chris_backend/plugininstances/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ def get_output_path(self):
Custom method to get the output directory for files generated by
the plugin instance object.
"""
return self.output_folder.path
return str(self.output_folder.path)


@receiver(post_delete, sender=PluginInstance)
def auto_delete_output_folder_with_plugin_instance(sender, instance, **kwargs):
try:
instance.output_folder.delete()
instance.output_folder.parent.delete() # delete parent of the output data folder
except Exception:
pass

Expand Down
24 changes: 13 additions & 11 deletions chris_backend/plugininstances/services/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

from core.storage import connect_storage
from core.utils import json_zip2str
from core.models import ChrisInstance, ChrisFolder, ChrisLinkFile
from core.models import ChrisInstance, ChrisFolder, ChrisFile, ChrisLinkFile
from plugininstances.models import PluginInstance, PluginInstanceLock
from userfiles.models import UserFile

Expand Down Expand Up @@ -377,24 +377,26 @@ def get_previous_output_path(self):
the eventual consistency.
"""
job_id = self.str_job_id
previous = self.c_plugin_inst.previous
output_path = previous.get_output_path()
output_folders = previous.output_folder.get_descendants()
fnames = []
for folder in output_folders:
fnames.extend([f.fname.name for f in folder.chris_files.all()])
output_path = self.c_plugin_inst.previous.get_output_path()
prefix = output_path + '/' # avoid sibling folders with paths that start with path

set_fnames = {f.fname.name for f in ChrisFile.objects.filter(
fname__startswith=prefix)}

for i in range(20): # loop to deal with eventual consistency
try:
l_ls = self.storage_manager.ls(output_path)
except Exception as e:
logger.error(f'[CODE06,{job_id}]: Error while listing storage files '
f'in {output_path}, detail: {str(e)}')
else:
if all(obj in l_ls for obj in fnames):
if set_fnames.issubset(set(l_ls)):
return output_path
time.sleep(3)

logger.error(f'[CODE11,{job_id}]: Error while listing storage files in '
f'{output_path}, detail: Presumable eventual consistency problem')

self.c_plugin_inst.error_code = 'CODE11'
raise NameError('Presumable eventual consistency problem.')

Expand Down Expand Up @@ -665,13 +667,13 @@ def save_plugin_instance_final_status(self):
logger.info(f"Setting output folder's permissions for job {job_id} ...")

for group in self.c_plugin_inst.feed.shared_groups.all():
self.c_plugin_inst.output_folder.grant_group_permission(group, 'w')
self.c_plugin_inst.output_folder.parent.grant_group_permission(group, 'w')

for user in self.c_plugin_inst.feed.shared_users.all():
self.c_plugin_inst.output_folder.grant_user_permission(user, 'w')
self.c_plugin_inst.output_folder.parent.grant_user_permission(user, 'w')

if self.c_plugin_inst.feed.public:
self.c_plugin_inst.output_folder.grant_public_access()
self.c_plugin_inst.output_folder.parent.grant_public_access()

logger.info(f"Saving job {job_id} DB status as '{self.c_plugin_inst.status}'")
self.c_plugin_inst.end_date = timezone.now()
Expand Down
Loading