def set_metadata(self, name, metadata): session = db.get_session() try: db_state = utils.model_query(models.StateInfo, session).filter_by( name=name, ).with_lockmode('update').one() db_state.s_metadata = metadata except sqlalchemy.orm.exc.NoResultFound: db_state = models.StateInfo(name=name, s_metadata=metadata) session.add(db_state) finally: session.flush()
def set_metadata(self, name, metadata): session = db.get_session() with session.begin(): try: q = utils.model_query(models.StateInfo, session) q = q.filter(models.StateInfo.name == name) q = q.with_lockmode('update') db_state = q.one() db_state.s_metadata = metadata except sqlalchemy.orm.exc.NoResultFound: db_state = models.StateInfo(name=name, s_metadata=metadata) session.add(db_state)
def set_state(self, name, state): session = db.get_session() with session.begin(): try: q = utils.model_query(models.StateInfo, session).filter_by( name=name, ).with_lockmode('update') db_state = q.one() db_state.state = state except sqlalchemy.orm.exc.NoResultFound: db_state = models.StateInfo(name=name, state=state) session.add(db_state) return bool(db_state.state)
def set_state(self, name, state): session = db.get_session() with session.begin(): try: q = utils.model_query(models.StateInfo, session) q = q.filter(models.StateInfo.name == name) q = q.with_for_update() db_state = q.one() db_state.state = state except sqlalchemy.orm.exc.NoResultFound: db_state = models.StateInfo(name=name, state=state) session.add(db_state) return db_state.state