def release(table: Table, _id: str) -> bool: """ Releases lock on object. Returns False if the object does not exist or is already released. """ if table.update({"_id": _id, "_mutex": False}, ["_id"]): return True return False
def lock(table: Table, id: str, attempt=0, max_attempts=0) -> bool: """ Attempts to acquire lock on object """ if table.update({"_id": id, "_mutex": True}, ["_id"]): return True if attempt < max_attempts: return _BaseOperations.lock(table, id, attempt + 1, max_attempts) else: return False
def update(table: Table, data: dict) -> bool: if data.get("id") is not None: data["_id"] = data["id"] del data["id"] return table.update(data)