本文整理汇总了Python中cocaine.services.Service类的典型用法代码示例。如果您正苦于以下问题:Python Service类的具体用法?Python Service怎么用?Python Service使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_node_service_bad_on_read
def test_node_service_bad_on_read():
io = IOLoop.current()
node = Service("node", endpoints=[["localhost", 10053]], io_loop=io)
malformed_message = msgpack.packb([-999, 0])
node.on_read(malformed_message)
message = msgpack.packb([-999, 0, []])
node.on_read(message)
示例2: f
def f():
io = IOLoop.current()
node = Service("node", endpoints=[["localhost", 10053]], io_loop=io)
channel = yield node.list()
app_list = yield channel.rx.get()
assert isinstance(app_list, list)
raise gen.Return("OK")
示例3: stop_app
def stop_app(self, appname):
succeed = list()
failed = list()
hosts_count = len(self.hosts)
for i, host in enumerate(self.hosts):
log.info("Stop %s at host %d/%d %s" % (appname, i, hosts_count, host))
nodeinstance = None
try:
nodeinstance = Service("node", blockingConnect=False)
yield nodeinstance.connect(host=host)
res = yield app.Stop(nodeinstance, appname).execute()
self.logcallback(str(res) + "\n")
except Exception as e:
item = "Unable to connect to node at host %s %s\n" % (host, e)
log.error(item)
self.logcallback(item)
failed.append(host)
else:
item = "App %s has been stoped successfully\n" % appname
log.info(item)
self.logcallback(item)
succeed.append(host)
finally:
if nodeinstance is not None:
nodeinstance.disconnect()
yield (succeed, failed)
示例4: test_node_service_bad_on_read
def test_node_service_bad_on_read():
io = CocaineIO.instance()
node = Service("node", host="localhost", port=10053, loop=io)
malformed_message = msgpack.packb([-999, 0])
node.on_read(malformed_message)
message = msgpack.packb([-999, 0, []])
node.on_read(message)
示例5: main
def main():
warning = "1; app status broken: "
error = "2; depth is full: "
node = Service("node")
try:
chan = yield node.list()
except:
print "1; error while connect to service node"
exit(0)
app_list = yield chan.rx.get()
for name in app_list:
app = Service(name)
try:
chan = yield app.info()
info = yield chan.rx.get()
if info["queue"]["depth"] == info["queue"]["capacity"]:
if name != "v012-karma":
error = error + name + ","
except:
warning = warning + name + ","
if error != "2; depth is full: ":
print (error)
elif warning != "1; app status broken: ":
print (warning)
else:
print ("0;Ok")
示例6: f
def f():
io = IOLoop.current()
storage = Service("storage", endpoints=[["localhost", 10053]], io_loop=io)
channel = yield storage.find('app', ['apps'])
app_list = yield channel.rx.get()
assert isinstance(app_list, list)
raise gen.Return("OK")
示例7: get_service
def get_service(self, name, request):
# cache isn't full for the current application
if len(self.cache[name]) < self.spoolSize:
logger = request.logger
try:
app = Service(name, locator=self.locator, timeout=RESOLVE_TIMEOUT)
logger.info("%s: creating an instance of %s", app.id, name)
self.cache[name].append(app)
yield app.connect(request.traceid)
logger.info("%s: connect to an app %s endpoint %s ",
app.id, app.name, "{0}:{1}".format(*app.address))
timeout = (1 + random.random()) * self.refreshPeriod
self.io_loop.call_later(timeout, self.move_to_inactive(app, name))
except Exception as err:
logger.error("%s: unable to connect to `%s`: %s", app.id, name, err)
if app in self.cache[name]:
self.cache[name].remove(app)
raise gen.Return()
else:
raise gen.Return(app)
# get an instance from cache
chosen = random.choice(self.cache[name])
raise gen.Return(chosen)
示例8: func3
def func3(args):
print "Start"
s = Service("storage")
try:
k = yield s.write("A", "A", "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK", [])
except Exception as err:
print err
print "END"
示例9: main
def main():
locator = Service("locator")
try:
yield locator.connect()
except:
print "2; error while connect to locator"
exit(1)
print "0;Ok"
示例10: process_synchronous
def process_synchronous(self, cocaine_service_name, cocaine_method, data):
"""Synchronous Cocaine worker handling."""
self.log("In process_synchronous()")
service = Service(cocaine_service_name)
response = service.enqueue(cocaine_method, msgpack.dumps(data)).get()
service.disconnect()
self.log("process_synchronous() finished")
return response
示例11: process_asynchronous
def process_asynchronous(self, cocaine_service_name, cocaine_method, data):
"""Run selected service and get all chunks as generator."""
self.log("In process_asynchronous()")
service = Service(cocaine_service_name)
chunks_g = service.enqueue(cocaine_method, msgpack.dumps(data))
yield chunks_g
service.disconnect()
self.log("process_asynchronous() finished")
示例12: get_service_with_seed
def get_service_with_seed(self, name, seed, request):
logger = request.logger
app = Service(name, seed=seed, locator=self.locator)
try:
logger.info("%s: creating an instance of %s, seed %s", app.id, name, seed)
yield app.connect(logger.traceid)
except Exception as err:
logger.error("%s: unable to connect to `%s`: %s", app.id, name, err)
raise gen.Return()
raise gen.Return(app)
示例13: raw
def raw(request, response):
inc = yield request.read()
goapp = Service("gococaine")
storage = Service("storage")
# Send data to the go application
response.write("Send data to the go application")
key = yield goapp.enqueue("process", str(inc))
response.write("Data was processed and saved to the storage, key: %s" % key)
# Read data from storage
res = yield storage.read("namespace", key)
response.write(res)
response.close()
示例14: main
def main():
locator = Service("locator")
try:
yield locator.connect()
except:
print "1; error while connect to locator"
exit(1)
try:
chan = yield locator.resolve("graphite")
result = yield chan.rx.get()
except:
print "2; error while resolv service graphite"
exit(1)
print "0;Ok"
示例15: execute
def execute(self):
appNames = yield self.node.list()
appInfoList = {}
for appName in appNames:
info = ''
try:
app = Service(appName, blockingConnect=False)
yield app.connectThroughLocator(self.locator)
info = yield app.info()
except Exception as err:
info = str(err)
finally:
appInfoList[appName] = info
result = {
'apps': appInfoList
}
yield result