本文整理汇总了Python中cocaine.services.Service.children_subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Service.children_subscribe方法的具体用法?Python Service.children_subscribe怎么用?Python Service.children_subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cocaine.services.Service
的用法示例。
在下文中一共展示了Service.children_subscribe方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CocaineProxy
# 需要导入模块: from cocaine.services import Service [as 别名]
# 或者: from cocaine.services.Service import children_subscribe [as 别名]
#.........这里部分代码省略.........
watch_channel = yield self.unicorn.subscribe(path, version)
while True:
value, version = yield watch_channel.rx.get()
self.logger.info("got sampling updates for %s: version %d value %.2f", name, version, value)
try:
weight = float(value)
self.sampled_apps[name] = weight
except ValueError as err:
self.logger.error("sample value %s for %s can NOT be converted: %s. Use %f",
value, name, err, self.default_tracing_chance)
self.sampled_apps[name] = self.default_tracing_chance
except ServiceError as err:
# verify that the err is `zookeeper: no node [-101]``
if err.code != -101:
self.logger.error("watching of `%s` raised an unexpected service error (cat. %d): %s", name, err.category, err)
except Exception as err:
self.logger.error("watching of %s error: %s", name, err)
finally:
self.logger.info("stop watching for sampling updates of %s", name)
self.sampled_apps.pop(name, None)
try:
watch_channel.tx.close()
except Exception:
pass
@gen.coroutine
def on_sampling_updates(self):
maximum_timeout = 32 # sec
timeout = 1 # sec
listing_version = 0
while True:
try:
listing_channel = yield self.unicorn.children_subscribe(self.tracing_conf_path, listing_version)
while True:
listing_version, apps = yield listing_channel.rx.get()
self.logger.info("on_sampling_updates: version %d value %s", listing_version, apps)
for app in (i for i in apps if i not in self.sampled_apps):
self.watch_app(app, self.tracing_conf_path + "/" + app)
except Exception as err:
timeout = min(timeout << 1, maximum_timeout)
listing_version = 0
self.logger.error("error occurred while subscribing for sampling updates %s. Sleep %d",
err, timeout)
yield gen.sleep(timeout)
@gen.coroutine
def watch_app_timeouts(self, name, path):
version = 0
self.timeouts[name] = {}
try:
self.logger.info("start watching for timeouts updates of %s", name)
watch_channel = yield self.unicorn.subscribe(path, version)
while True:
value, version = yield watch_channel.rx.get()
self.logger.info("got timeouts updates for %s: version %d value %s", name, version, value)
if isinstance(value, dict):
self.timeouts[name] = value
else:
self.logger.error("timeout value %s for %s is not dict", value, name)
self.timeouts[name] = {}
except ServiceError as err:
# verify that the err is `zookeeper: no node [-101]``
if err.code != -101:
self.logger.error("watching of `%s` raised an unexpected service error (cat. %d): %s", name, err.category, err)
except Exception as err: