Пример #1
0
def create_trigger_db_from_rule(rule):
    trigger_dict = _get_trigger_dict_given_rule(rule)
    existing_trigger_db = _get_trigger_db(trigger_dict)
    # For simple triggertypes (triggertype with no parameters), we create a trigger when
    # registering triggertype. So if we hit the case that there is no trigger in db but
    # parameters is empty, then this case is a run time error.
    if not trigger_dict.get('parameters', {}) and not existing_trigger_db:
        raise TriggerDoesNotExistException(
            'A simple trigger should have been created when registering '
            'triggertype. Cannot create trigger: %s.' % (trigger_dict))

    if not existing_trigger_db:
        return create_or_update_trigger_db(trigger_dict)

    return existing_trigger_db
Пример #2
0
def create_trigger_db_from_rule(rule):
    trigger_dict = _get_trigger_dict_given_rule(rule)
    existing_trigger_db = _get_trigger_db(trigger_dict)
    # For simple triggertypes (triggertype with no parameters), we create a trigger when
    # registering triggertype. So if we hit the case that there is no trigger in db but
    # parameters is empty, then this case is a run time error.
    if not trigger_dict.get('parameters', {}) and not existing_trigger_db:
        raise TriggerDoesNotExistException(
            'A simple trigger should have been created when registering '
            'triggertype. Cannot create trigger: %s.' % (trigger_dict))

    if not existing_trigger_db:
        trigger_db = create_or_update_trigger_db(trigger_dict)
    else:
        trigger_db = existing_trigger_db

    # Special reference counting for trigger with parameters.
    # if trigger_dict.get('parameters', None):
    #     Trigger.update(trigger_db, inc__ref_count=1)

    return trigger_db