def analyze_failed_registration_nodes():
    """ If we can just retry the archive, but we can only do that if the
    ORIGINAL node hasn't changed.
    """
    # Get the registrations that are messed up
    failed_registration_nodes = Registration.find_failed_registrations()

    # Build up a list of dictionaries with info about these failed nodes
    failed_registration_info = []
    for broken_registration in failed_registration_nodes:
        unacceptable_node_logs_after_date = list(
            broken_registration.registered_from.get_logs_queryset(Auth(broken_registration.registered_from.creator))
            .filter(date__gt=broken_registration.registered_date)
            .exclude(action__in=fa.LOG_WHITELIST)
            .exclude(action__in=fa.LOG_GREYLIST)
            .values_list('action', flat=True)
        )

        # Does it have any addons?
        addon_list = [
            addon for addon in ADDONS_REQUESTED
            if broken_registration.registered_from.has_addon(addon)
            and addon not in {'osfstorage', 'wiki'}
        ]
        has_addons = bool(addon_list)

        # Any registrations succeeded after the stuck one?
        # Not sure why broken_registration.registered_from.registrations was always 0 locally...
        succeeded_registrations_after_failed = []
        for other_reg in Registration.objects.filter(
            registered_from=broken_registration.registered_from,
            registered_date__gt=broken_registration.registered_date
        ):
            if other_reg.sanction:
                if other_reg.sanction.is_approved:
                    succeeded_registrations_after_failed.append(other_reg._id)
            else:
                succeeded_registrations_after_failed.append(other_reg._id)

        can_be_reset = fa.verify(broken_registration)
        logger.info('Found broken registration {}'.format(broken_registration._id))
        failed_registration_info.append(
            {
                'registration': broken_registration._id,
                'registered_date': broken_registration.registered_date,
                'original_node': broken_registration.registered_from._id,
                'logs_on_original_after_registration_date': unacceptable_node_logs_after_date,
                'has_addons': has_addons,
                'addon_list': addon_list,
                'succeeded_registrations_after_failed': succeeded_registrations_after_failed,
                'can_be_reset': can_be_reset,
                'registered_from_public': broken_registration.registered_from.is_public,
            }
        )

    return failed_registration_info
Beispiel #2
0
    def post(self, request, *args, **kwargs):
        stuck_reg = self.get_object()
        if Registration.find_failed_registrations().filter(
                id=stuck_reg.id).exists():
            stuck_reg.delete_registration_tree(save=True)
            messages.success(request, 'The registration has been deleted')
        else:
            messages.error(
                request, 'This registration may not technically be stuck,'
                ' if the problem persists get a developer to fix it.')

        return redirect(self.get_success_url())
def mark_failed_registration_files_as_deleted(batch_size, dry_run=False):
    """
    These registrations have ArchiveJobs stuck in initial state after the archive timeout period.
    """
    failed_registrations = Registration.find_failed_registrations(
        days_stuck=STUCK_FILES_DELETE_TIMEOUT)
    logger.info(
        f'{"[DRY-RUN]" if dry_run else ""} There are {failed_registrations.count()} registrations that are stuck having there files marked as deleted'
    )

    for reg in failed_registrations.annotate(fc=Count('files')).filter(
            fc__gte=1)[:batch_size]:
        reg.delete_registration_tree(save=True)
        files_to_be_deleted = reg.files.all()
        logger.info(
            f'{"[DRY-RUN]" if dry_run else ""} There are {files_to_be_deleted.count()} files deleted from stuck registration ({reg._id})'
        )
        for file in files_to_be_deleted:
            if not dry_run:
                file.delete()
Beispiel #4
0
 def get_queryset(self):
     # Django template does not like attributes with underscores for some reason, so we annotate.
     return Registration.find_failed_registrations().annotate(
         guid=F('guids___id'))