本文整理汇总了Python中cluster.Cluster.lock_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Cluster.lock_by_id方法的具体用法?Python Cluster.lock_by_id怎么用?Python Cluster.lock_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cluster.Cluster
的用法示例。
在下文中一共展示了Cluster.lock_by_id方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quit
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import lock_by_id [as 别名]
def quit(host, port, cluster_id, quit_cluster):
logging.info('Node %s:%d quit from cluster [ %d ]', host, port, cluster_id)
instance = pick_by(host, port)
if instance.assignee is None:
return
Cluster.lock_by_id(instance.assignee_id)
quit_cluster(host, port)
instance.assignee = None
db.session.add(instance)
示例2: pick_and_launch
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import lock_by_id [as 别名]
def pick_and_launch(host, port, cluster_id, start_cluster):
logging.info('Launching cluster for [ %d ]', cluster_id)
node = pick_by(host, port)
if node.assignee is not None:
raise errors.AppMutexError()
cluster = Cluster.lock_by_id(cluster_id)
start_cluster(node.host, node.port)
node.assignee = cluster
db.session.add(node)
示例3: pick_and_replicate
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import lock_by_id [as 别名]
def pick_and_replicate(master_host, master_port, slave_host, slave_port,
replicate_node):
master_node = pick_by(master_host, master_port)
if master_node.assignee_id is None:
raise ValueError('node not in cluster')
cluster = Cluster.lock_by_id(master_node.assignee_id)
slave_node = pick_by(slave_host, slave_port)
replicate_node(master_host, master_port, slave_host, slave_port)
slave_node.assignee = cluster
db.session.add(slave_node)
示例4: pick_and_expand
# 需要导入模块: from cluster import Cluster [as 别名]
# 或者: from cluster.Cluster import lock_by_id [as 别名]
def pick_and_expand(host, port, cluster_id, join_node):
cluster = Cluster.lock_by_id(cluster_id)
if len(cluster.nodes) == 0:
raise ValueError('no node in such cluster')
new_node = db.session.query(RedisNode).filter(
RedisNode.host == host,
RedisNode.port == port,
RedisNode.assignee_id == None).with_for_update().first()
if new_node is None:
raise ValueError('no such node')
join_node(cluster.nodes[0].host, cluster.nodes[0].port, new_node.host,
new_node.port)
new_node.assignee_id = cluster_id
db.session.add(new_node)