def archive_registrations_on_IA(dry_run=False, batch_size=100, guids=None): if guids: registrations = Registration.objects.filter(guids___id__in=guids) else: # randomize order so large registrations won't block all pigeon workers, # and stuck registrations won't block repeatedly registrations = Registration.find_ia_backlog().order_by( '?')[:batch_size] logger.info(f'{registrations.count()} to be archived in batch') for registration in registrations: time.sleep(.1) # Don't DDOS self if not dry_run: logger.info(f'archiving {registration._id}') requests_retry_session().post( f'{settings.OSF_PIGEON_URL}archive/{registration._id}') else: logger.info(f'DRY RUN for archiving {registration._id}')
def get_queryset(self): # Django template does not like attributes with underscores for some reason, so we annotate. return Registration.find_ia_backlog().annotate(guid=F('guids___id'))