當前位置: 首頁>>代碼示例>>Python>>正文


Python services.Service類代碼示例

本文整理匯總了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)
開發者ID:Alukardd,項目名稱:cocaine-framework-python,代碼行數:7,代碼來源:test_main.py

示例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")
開發者ID:gabrielferreira,項目名稱:cocaine-framework-python,代碼行數:7,代碼來源:test_main.py

示例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)
開發者ID:noxiouz,項目名稱:infinite-flow,代碼行數:26,代碼來源:nodecluster.py

示例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)
開發者ID:mwf,項目名稱:cocaine-framework-python,代碼行數:7,代碼來源:test_main.py

示例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")
開發者ID:borislitv,項目名稱:cocaine-script,代碼行數:26,代碼來源:cocaine-check-depth.py

示例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")
開發者ID:Alukardd,項目名稱:cocaine-framework-python,代碼行數:7,代碼來源:test_main.py

示例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)
開發者ID:werehuman,項目名稱:cocaine-tools,代碼行數:25,代碼來源:proxy.py

示例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"
開發者ID:ijon,項目名稱:cocaine-framework-python,代碼行數:8,代碼來源:chaining.py

示例9: main

def main():
    locator = Service("locator")
    try:
        yield locator.connect()
    except:
        print "2; error while connect to locator"
        exit(1)
    print "0;Ok"
開發者ID:borislitv,項目名稱:cocaine-script,代碼行數:8,代碼來源:cocaine-check-locator.py

示例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
開發者ID:mwf,項目名稱:tornado_cocaine_test,代碼行數:9,代碼來源:handlers.py

示例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")
開發者ID:mwf,項目名稱:tornado_cocaine_test,代碼行數:10,代碼來源:handlers.py

示例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)
開發者ID:werehuman,項目名稱:cocaine-tools,代碼行數:11,代碼來源:proxy.py

示例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()
開發者ID:elmato,項目名稱:flask-cocaine-pycon,代碼行數:12,代碼來源:main.py

示例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"
開發者ID:borislitv,項目名稱:cocaine-script,代碼行數:14,代碼來源:cocaine-check-graphite.py

示例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
開發者ID:ApelSYN,項目名稱:cocaine-tools,代碼行數:17,代碼來源:common.py


注:本文中的cocaine.services.Service類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。