@periodic_task(serializer='pickle', run_every=crontab(hour='*', minute=0), queue=settings.CELERY_PERIODIC_QUEUE, ignore_result=True)
def run_case_update_rules(now=None):
    domains = AutomaticUpdateRule.objects.filter(active=True, deleted=False, workflow=AutomaticUpdateRule.WORKFLOW_CASE_UPDATE).values_list('domain', flat=True).distinct().order_by('domain')
    hour_to_run = (now.hour if now else datetime.utcnow().hour)
    for domain in domains:
        if ((not any_migrations_in_progress(domain)) and (not DISABLE_CASE_UPDATE_RULE_SCHEDULED_TASK.enabled(domain))):
            domain_obj = Domain.get_by_name(domain)
            if (domain_obj.auto_case_update_hour is None):
                domain_hour = settings.RULE_UPDATE_HOUR
            else:
                domain_hour = domain_obj.auto_case_update_hour
            if (hour_to_run == domain_hour):
                run_case_update_rules_for_domain.delay(domain, now)
@periodic_task(serializer='pickle', run_every=crontab(hour='*', minute=0), queue=settings.CELERY_PERIODIC_QUEUE, ignore_result=True)
def run_case_update_rules(now=None):
    domains = AutomaticUpdateRule.objects.filter(active=True, deleted=False, workflow=AutomaticUpdateRule.WORKFLOW_CASE_UPDATE).values_list('domain', flat=True).distinct().order_by('domain')
    hour_to_run = (now.hour if now else datetime.utcnow().hour)
    for domain in domains:
        if ((not any_migrations_in_progress(domain)) and (not DISABLE_CASE_UPDATE_RULE_SCHEDULED_TASK.enabled(domain))):
            domain_obj = Domain.get_by_name(domain)
            if (domain_obj.auto_case_update_hour is None):
                domain_hour = settings.RULE_UPDATE_HOUR
            else:
                domain_hour = domain_obj.auto_case_update_hour
            if (hour_to_run == domain_hour):
                run_case_update_rules_for_domain.delay(domain, now)