本文整理匯總了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: