コード例 #1
0
def upsert_message(message_name, cooldown_ts, trigger_event_id, screen,
                   expiry_millis, priority):
    '''
    Add or update a message. Returns new or updated message.
    '''
    with session_scope() as session:
        message = session.query(model.Message).filter(
            model.Message.name == message_name).one_or_none()
        if message is not None:
            message.cooldown_ts = cooldown_ts
            message.trigger_event_id = trigger_event_id
            message.screen = screen
            message.expiry_millis = expiry_millis
            message.priority = priority
        else:
            message = model.Message(name=message_name,
                                    cooldown_ts=cooldown_ts,
                                    trigger_event_id=trigger_event_id,
                                    screen=screen,
                                    expiry_millis=expiry_millis,
                                    priority=priority)
            session.add(message)
        session.commit()
        session.refresh(message)
    return message
コード例 #2
0
def upsert_message(message_name, cooldown_ts, trigger_event_id, screen):
    '''
    Add or update a message.
    '''
    session = get_session()
    message = session.query(model.Message).filter(model.Message.name == message_name).one_or_none()
    if message is not None:
        message.cooldown_ts = cooldown_ts
        message.trigger_event_id = trigger_event_id
        message.screen = screen
    else:
        message = model.Message(name=message_name, cooldown_ts=cooldown_ts, trigger_event_id=trigger_event_id, screen=screen)
        session.add(message)
    session.commit()
    return message
コード例 #3
0
ファイル: database.py プロジェクト: adioslabs/pushkin
def upsert_message(message_name, cooldown_ts, trigger_event_id, screen,
                   expiry_millis):
    '''
    Add or update a message. Returns new or updated message.
    '''
    session = get_session()
    message = session.query(model.Message).filter(
        model.Message.name == message_name).one_or_none()
    if message is not None:
        message.cooldown_ts = cooldown_ts
        message.trigger_event_id = trigger_event_id
        message.screen = screen
        message.expiry_millis = expiry_millis
    else:
        message = model.Message(name=message_name,
                                cooldown_ts=cooldown_ts,
                                trigger_event_id=trigger_event_id,
                                screen=screen,
                                expiry_millis=expiry_millis)
        session.add(message)
    session.commit()
    session.refresh(message)
    session.close()
    return message