Beispiel #1
0
def node_lock_acquire(node_id, action_id):
    with session_for_write() as session:
        lock = session.query(models.NodeLock).get(node_id)
        if lock is None:
            lock = models.NodeLock(node_id=node_id, action_id=action_id)
            session.add(lock)

        return lock.action_id
Beispiel #2
0
def node_lock_steal(node_id, action_id):
    with session_for_write() as session:
        lock = session.query(models.NodeLock).get(node_id)
        if lock is not None:
            lock.action_id = action_id
            lock.save(session)
        else:
            lock = models.NodeLock(node_id=node_id, action_id=action_id)
            session.add(lock)
        return lock.action_id