本文整理汇总了Python中juliabox.cloud.Compute.get_image_recentness方法的典型用法代码示例。如果您正苦于以下问题:Python Compute.get_image_recentness方法的具体用法?Python Compute.get_image_recentness怎么用?Python Compute.get_image_recentness使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类juliabox.cloud.Compute
的用法示例。
在下文中一共展示了Compute.get_image_recentness方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_cluster_leader
# 需要导入模块: from juliabox.cloud import Compute [as 别名]
# 或者: from juliabox.cloud.Compute import get_image_recentness [as 别名]
def is_cluster_leader():
self_id = Compute.get_instance_id()
cluster = Compute.get_install_id()
instances = Compute.get_all_instances()
leader = JBoxDynConfig.get_cluster_leader(cluster)
img_recentness = Compute.get_image_recentness()
JBoxDB.log_debug("cluster: %s. instances: %s. leader: %s. image recentness: %d",
cluster, repr(instances), repr(leader), img_recentness)
# if none set, or set instance is dead elect self as leader, but wait till next cycle to prevent conflicts
if (leader is None) or (leader not in instances) and (img_recentness >= 0):
JBoxDB.log_info("setting self (%s) as cluster leader", self_id)
try:
JBoxDynConfig.set_cluster_leader(cluster, self_id)
except:
JBoxDB.log_info("error setting self (%s) as cluster leader, will retry", self_id)
return False
is_leader = (leader == self_id)
# if running an older ami, step down from cluster leader
if (img_recentness < 0) and is_leader:
JBoxDB.log_info("unmarking self (%s) as cluster leader", self_id)
JBoxDynConfig.unset_cluster_leader(cluster)
return False
return is_leader