@serial_task('{domain}-{case_type}-{db}', timeout=((36 * 60) * 60), max_retries=0, queue='case_rule_queue')
def run_case_update_rules_for_domain_and_db(domain, now, run_id, case_type, db=None):
    all_rules = AutomaticUpdateRule.by_domain(domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE)
    rules = list(all_rules.filter(case_type=case_type))
    boundary_date = AutomaticUpdateRule.get_boundary_date(rules, now)
    iterator = AutomaticUpdateRule.iter_cases(domain, case_type, boundary_date, db=db)
    run = iter_cases_and_run_rules(domain, iterator, rules, now, run_id, case_type, db)
    if (run.status == DomainCaseRuleRun.STATUS_FINISHED):
        for rule in rules:
            AutomaticUpdateRule.objects.filter(pk=rule.pk).update(last_run=now)
@serial_task('{domain}-{case_type}-{db}', timeout=((36 * 60) * 60), max_retries=0, queue='case_rule_queue')
def run_case_update_rules_for_domain_and_db(domain, now, run_id, case_type, db=None):
    all_rules = AutomaticUpdateRule.by_domain(domain, AutomaticUpdateRule.WORKFLOW_CASE_UPDATE)
    rules = list(all_rules.filter(case_type=case_type))
    boundary_date = AutomaticUpdateRule.get_boundary_date(rules, now)
    iterator = AutomaticUpdateRule.iter_cases(domain, case_type, boundary_date, db=db)
    run = iter_cases_and_run_rules(domain, iterator, rules, now, run_id, case_type, db)
    if (run.status == DomainCaseRuleRun.STATUS_FINISHED):
        for rule in rules:
            AutomaticUpdateRule.objects.filter(pk=rule.pk).update(last_run=now)