@task(serializer='pickle', queue='case_rule_queue')
def run_case_update_rules_for_domain(domain, now=None):
    now = (now or datetime.utcnow())
    domain_rules = AutomaticUpdateRule.by_domain(domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE)
    all_rule_case_types = set(domain_rules.values_list('case_type', flat=True))
    for case_type in all_rule_case_types:
        run_record = DomainCaseRuleRun.objects.create(domain=domain, started_on=datetime.utcnow(), status=DomainCaseRuleRun.STATUS_RUNNING, case_type=case_type)
        for db in get_db_aliases_for_partitioned_query():
            run_case_update_rules_for_domain_and_db.delay(domain, now, run_record.pk, case_type, db=db)
@task(serializer='pickle', queue='case_rule_queue')
def run_case_update_rules_for_domain(domain, now=None):
    now = (now or datetime.utcnow())
    domain_rules = AutomaticUpdateRule.by_domain(domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE)
    all_rule_case_types = set(domain_rules.values_list('case_type', flat=True))
    for case_type in all_rule_case_types:
        run_record = DomainCaseRuleRun.objects.create(domain=domain, started_on=datetime.utcnow(), status=DomainCaseRuleRun.STATUS_RUNNING, case_type=case_type)
        for db in get_db_aliases_for_partitioned_query():
            run_case_update_rules_for_domain_and_db.delay(domain, now, run_record.pk, case_type, db=db)