3636from addons .osfstorage .models import OsfStorageFile , OsfStorageFolder , OsfStorageFileNode
3737from framework import sentry
3838from framework .exceptions import HTTPError
39+ from osf import features
3940from osf .models import AbstractNode , Node , NodeLog , Registration , BaseFileNode
4041from osf .models .files import TrashedFileNode
42+ from osf .utils .requests import get_current_request
4143from osf .exceptions import RegistrationStuckRecoverableException , RegistrationStuckBrokenException
4244from api .base .utils import waterbutler_api_url_for
45+ from api .waffle .utils import flag_is_active
4346from scripts import utils as script_utils
4447from website .archiver import ARCHIVER_SUCCESS
4548from website .settings import ARCHIVE_TIMEOUT_TIMEDELTA , ARCHIVE_PROVIDER , COOKIE_NAME
@@ -149,9 +152,11 @@ def complete_archive_target(reg, addon_short_name):
149152
150153def perform_wb_copy (reg , node_settings , delete_collisions = False , skip_collisions = False ):
151154 src , dst , user = reg .archive_job .info ()
152- if dst .files .filter (name = node_settings .archive_folder_name .replace ('/' , '-' )).exists ():
155+ dst_storage = dst .get_addon ('osfstorage' )
156+ archive_name = node_settings .archive_folder_name .replace ('/' , '-' )
157+ if dst_storage .get_root ().children .filter (name = archive_name ).exists ():
153158 if not delete_collisions and not skip_collisions :
154- raise Exception ('Archive folder for {} already exists. Investigate manually and rerun with either --delete-collisions or --skip-collisions' )
159+ raise Exception (f 'Archive folder for { archive_name } already exists. Investigate manually and rerun with either --delete-collisions or --skip-collisions' )
155160 if delete_collisions :
156161 archive_folder = dst .files .exclude (type = 'osf.trashedfolder' ).get (name = node_settings .archive_folder_name .replace ('/' , '-' ))
157162 logger .info (f'Removing { archive_folder } ' )
@@ -393,12 +398,23 @@ def archive(registration, *args, permissible_addons=DEFAULT_PERMISSIBLE_ADDONS,
393398 logger .info (f'Preparing to archive { reg ._id } ' )
394399 for short_name in permissible_addons :
395400 node_settings = reg .registered_from .get_addon (short_name )
401+ if not node_settings and short_name != 'osfstorage' and flag_is_active (get_current_request (), features .ENABLE_GV ):
402+ # get_addon() returns None for addons when archive is running inside of
403+ # the celery task. In this case, try to get addon settings from the GV
404+ try :
405+ from website .archiver .tasks import get_addon_from_gv
406+ node_settings = get_addon_from_gv (reg .registered_from , short_name , reg .registered_from .creator )
407+ except Exception as e :
408+ logger .warning (f'Could not load { short_name } from GV: { e } ' )
409+
396410 if not hasattr (node_settings , '_get_file_tree' ):
397411 # Excludes invalid or None-type
412+ logger .warning (f"Skipping { short_name } for { registration ._id } ." )
398413 continue
399414 if not node_settings .configured :
400415 if not allow_unconfigured :
401416 raise Exception (f'{ reg ._id } : { short_name } on { reg .registered_from ._id } is not configured. If this is permissible, re-run with `--allow-unconfigured`.' )
417+ logger .warning (f"{ short_name } is not configured for { registration ._id } ." )
402418 continue
403419 if not reg .archive_job .get_target (short_name ) or reg .archive_job .get_target (short_name ).status == ARCHIVER_SUCCESS :
404420 continue
@@ -486,7 +502,7 @@ def verify_registrations(registration_ids, permissible_addons):
486502 else :
487503 SKIPPED .append (reg )
488504
489- def check (reg ):
505+ def check (reg , * args , ** kwargs ):
490506 """Check registration status. Raise exception if registration stuck."""
491507 logger .info (f'Checking { reg ._id } ' )
492508 if reg .is_deleted :
@@ -503,7 +519,7 @@ def check(reg):
503519 still_archiving = not archive_tree_finished
504520 if still_archiving and root_job .datetime_initiated < expired_if_before :
505521 logger .warning (f'Registration { reg ._id } is stuck in archiving' )
506- if verify (reg ):
522+ if verify (reg , * args , ** kwargs ):
507523 raise RegistrationStuckRecoverableException (f'Registration { reg ._id } is stuck and verified recoverable' )
508524 else :
509525 raise RegistrationStuckBrokenException (f'Registration { reg ._id } is stuck and verified broken' )
0 commit comments