(domain, survey_only=False)
The subscription changes are executed within a transaction, so
    we need to make sure any celery tasks only get started after the
    transaction commits.
The subscription changes are executed within a transaction, so
    we need to make sure any celery tasks only get started after the
    transaction commits.
The subscription changes are executed within a transaction so we need to make sure any celery tasks only get started after the transaction commits .
def _deactivate_schedules(domain, survey_only=False):
    """
    The subscription changes are executed within a transaction, so
    we need to make sure any celery tasks only get started after the
    transaction commits.
    """
    from corehq.messaging.tasks import initiate_messaging_rule_run

    for broadcast in _get_active_immediate_broadcasts(domain, survey_only=survey_only):
        AlertSchedule.objects.filter(schedule_id=broadcast.schedule_id).update(active=False)
        # We have to generate this function outside of this context otherwise it will be
        # bound to the name broadcast which changes over the course of iteration
        transaction.on_commit(get_refresh_alert_schedule_instances_call(broadcast))

    for broadcast in _get_active_scheduled_broadcasts(domain, survey_only=survey_only):
        TimedSchedule.objects.filter(schedule_id=broadcast.schedule_id).update(active=False)
        # We have to generate this function outside of this context otherwise it will be
        # bound to the name broadcast which changes over the course of iteration
        transaction.on_commit(get_refresh_timed_schedule_instances_call(broadcast))

    for rule in _get_active_scheduling_rules(domain, survey_only=survey_only):
        """
        Deactivating a scheduling rule involves only deactivating the schedule, and
        leaving the rule active. See ConditionalAlertListView.get_activate_ajax_response
        for more information.
        """
        with transaction.atomic():
            schedule = rule.get_schedule()
            if isinstance(schedule, AlertSchedule):
                AlertSchedule.objects.filter(schedule_id=schedule.schedule_id).update(active=False)
            elif isinstance(schedule, TimedSchedule):
                TimedSchedule.objects.filter(schedule_id=schedule.schedule_id).update(active=False)
            else:
                raise TypeError("Expected AlertSchedule or TimedSchedule")

            initiate_messaging_rule_run(rule)
def _deactivate_schedules ( domain , survey_only = False ) : from corehq . messaging . tasks import initiate_messaging_rule_run for broadcast in _get_active_immediate_broadcasts ( domain , survey_only = survey_only ) : AlertSchedule . objects . filter ( schedule_id = broadcast . schedule_id ) . update ( active = False ) # We have to generate this function outside of this context otherwise it will be # bound to the name broadcast which changes over the course of iteration transaction . on_commit ( get_refresh_alert_schedule_instances_call ( broadcast ) ) for broadcast in _get_active_scheduled_broadcasts ( domain , survey_only = survey_only ) : TimedSchedule . objects . filter ( schedule_id = broadcast . schedule_id ) . update ( active = False ) # We have to generate this function outside of this context otherwise it will be # bound to the name broadcast which changes over the course of iteration transaction . on_commit ( get_refresh_timed_schedule_instances_call ( broadcast ) ) for rule in _get_active_scheduling_rules ( domain , survey_only = survey_only ) : """
        Deactivating a scheduling rule involves only deactivating the schedule, and
        leaving the rule active. See ConditionalAlertListView.get_activate_ajax_response
        for more information.
        """ with transaction . atomic ( ) : schedule = rule . get_schedule ( ) if isinstance ( schedule , AlertSchedule ) : AlertSchedule . objects . filter ( schedule_id = schedule . schedule_id ) . update ( active = False ) elif isinstance ( schedule , TimedSchedule ) : TimedSchedule . objects . filter ( schedule_id = schedule . schedule_id ) . update ( active = False ) else : raise TypeError ( "Expected AlertSchedule or TimedSchedule" ) initiate_messaging_rule_run ( rule )