def check_data_migration_in_progress(domain, last_migration_check_time): utcnow = datetime.utcnow() if last_migration_check_time is None or ( utcnow - last_migration_check_time) > timedelta(minutes=1): return DATA_MIGRATION.enabled(domain), utcnow return False, last_migration_check_time
def any_migrations_in_progress(domain, strict=False): """Returns True if there are any migrations in progress where modifications to project forms and cases should be prevented """ return DATA_MIGRATION.enabled(domain) or DomainMigrationProgress.objects.filter( domain=domain, migration_status=MigrationStatus.IN_PROGRESS ).exists()
def all_domains_with_migrations_in_progress(): toggle_enabled = set(DATA_MIGRATION.get_enabled_domains()) flag_set = set( DomainMigrationProgress.objects.filter( migration_status=MigrationStatus.IN_PROGRESS).values_list( 'domain', flat=True)) return toggle_enabled | flag_set
def wrapped_view(request, domain, *args, **kwargs): if DATA_MIGRATION.enabled(domain): auth_logger.info("Request rejected domain=%s reason=%s request=%s", domain, "flag:migration", request.path) return HttpResponse('Service Temporarily Unavailable', content_type='text/plain', status=503) return view_func(request, domain, *args, **kwargs)
def run_case_update_rules(now=None): domains = (AutomaticUpdateRule.objects.filter( active=True, deleted=False).values_list('domain', flat=True).distinct().order_by('domain')) for domain in domains: if not DATA_MIGRATION.enabled(domain): run_case_update_rules_for_domain.delay(domain, now)
def get_items_to_be_processed(self, utcnow): for sms in QueuedSMS.get_queued_sms(): if DATA_MIGRATION.enabled(sms.domain): continue yield { 'id': sms.pk, 'key': json_format_datetime(sms.datetime_to_process), }
def run_case_update_rules(now=None): domains = (AutomaticUpdateRule .objects .filter(active=True, deleted=False) .values_list('domain', flat=True) .distinct() .order_by('domain')) for domain in domains: if not DATA_MIGRATION.enabled(domain): run_case_update_rules_for_domain.delay(domain, now)
def any_migrations_in_progress(domain, strict=False): """ Checks if any migrations at all are in progress for the domain Returns True if there are any migrations in progress where modifications to project forms and cases should be prevented. This does not include migrations that are marked as dry runs. """ return DATA_MIGRATION.enabled(domain) or DomainMigrationProgress.objects.filter( domain=domain, migration_status=MigrationStatus.IN_PROGRESS ).exists()
def process_view(self, request, view_func, view_args, view_kwargs): if hasattr(request, 'domain') and hasattr(request, 'couch_user'): if getattr(view_func, 'domain_migration_handled', False): return None if DATA_MIGRATION.enabled(request.domain): return TemplateResponse( request=request, template='domain/data_migration_in_progress.html', status=503, context={'domain': request.domain}) return None
def process_view(self, request, view_func, view_args, view_kwargs): if hasattr(request, 'domain') and hasattr(request, 'couch_user'): if getattr(view_func, 'domain_migration_handled', False): return None if DATA_MIGRATION.enabled(request.domain): return TemplateResponse( request=request, template='domain/data_migration_in_progress.html', status=503, ) return None
def any_migrations_in_progress(domain, strict=False): """ Checks if any migrations at all are in progress for the domain Returns True if there are any migrations in progress where modifications to project forms and cases should be prevented. This does not include migrations that are marked as dry runs. """ return DATA_MIGRATION.enabled( domain) or DomainMigrationProgress.objects.filter( domain=domain, migration_status=MigrationStatus.IN_PROGRESS).exists()
def wrapped_view(request, domain, *args, **kwargs): if DATA_MIGRATION.enabled(domain): return HttpResponse('Service Temporarily Unavailable', content_type='text/plain', status=503) return view_func(request, domain, *args, **kwargs)
def skip_domain(domain): return DATA_MIGRATION.enabled(domain) or any_migrations_in_progress(domain)
def enqueue_item(self, _id): domain = get_reminder_domain(_id) if DATA_MIGRATION.enabled(domain): return fire_reminder.delay(_id, domain)