(model_class, q_expression, load_source)
Optimized version of the generic paginate_query_across_partitioned_databases for case schedules

    queue_schedule_instances uses a lock to ensure that the same case_id cannot be queued within one
    hour of another instance
    The celery tasks handle_case_alert_schedule_instance and handle_case_timed_schedule_instance both
    use locks to ensure only one taks is operating on a case at one time. Each task also checks if the
    schedule is still valid on this case before processing it further

    Assumes that q_expression includes active = True
Optimized version of the generic paginate_query_across_partitioned_databases for case schedules
Optimized version of the generic paginate_query_across_partitioned_databases for case schedules
def _paginate_query_across_partitioned_databases(model_class, q_expression, load_source):
    """Optimized version of the generic paginate_query_across_partitioned_databases for case schedules

    queue_schedule_instances uses a lock to ensure that the same case_id cannot be queued within one
    hour of another instance
    The celery tasks handle_case_alert_schedule_instance and handle_case_timed_schedule_instance both
    use locks to ensure only one taks is operating on a case at one time. Each task also checks if the
    schedule is still valid on this case before processing it further

    Assumes that q_expression includes active = True
    """
    from corehq.messaging.scheduling.scheduling_partitioned.models import (
        CaseAlertScheduleInstance,
        CaseTimedScheduleInstance,
    )

    if model_class not in (CaseAlertScheduleInstance, CaseTimedScheduleInstance):
        raise TypeError("Expected CaseAlertScheduleInstance or CaseTimedScheduleInstance")

    db_names = get_db_aliases_for_partitioned_query()
    for db_name in db_names:
        for row in _paginate_query(db_name, model_class, q_expression, load_source):
            yield row
def _paginate_query_across_partitioned_databases ( model_class , q_expression , load_source ) : from corehq . messaging . scheduling . scheduling_partitioned . models import ( CaseAlertScheduleInstance , CaseTimedScheduleInstance , ) if model_class not in ( CaseAlertScheduleInstance , CaseTimedScheduleInstance ) : raise TypeError ( "Expected CaseAlertScheduleInstance or CaseTimedScheduleInstance" ) db_names = get_db_aliases_for_partitioned_query ( ) for db_name in db_names : for row in _paginate_query ( db_name , model_class , q_expression , load_source ) : yield row