当前位置: 首页>>代码示例>>Python>>正文


Python ServiceRunner.add_service方法代码示例

本文整理汇总了Python中nameko.runners.ServiceRunner.add_service方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceRunner.add_service方法的具体用法?Python ServiceRunner.add_service怎么用?Python ServiceRunner.add_service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nameko.runners.ServiceRunner的用法示例。


在下文中一共展示了ServiceRunner.add_service方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def main():
    config = {
        '_log': LOG,
        'AMQP_URI': 'amqp://guest:[email protected]:5672'
    }
    service_runner = ServiceRunner(config)
    service_runner.add_service(DatabaseService)

    service_runner.start()

    runnlet = eventlet.spawn(service_runner.wait)

    while True:
        try:
            runnlet.wait()
        except OSError as exc:
            if exc.errno == errno.EINTR:
                continue
            raise
        except KeyboardInterrupt:
            try:
                service_runner.stop()
            except KeyboardInterrupt:
                service_runner.kill()
        else:
            break
开发者ID:felippemr,项目名称:python_zookeeper_lock,代码行数:28,代码来源:database_service.py

示例2: test_runner_waits_raises_error

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def test_runner_waits_raises_error(fake_module):
    class Container(object):
        def __init__(self, service_cls, config):
            pass

        def start(self):
            pass

        def stop(self):
            pass

        def wait(self):
            raise Exception('error in container')

    fake_module.ServiceContainer = Container

    config = {'SERVICE_CONTAINER_CLS': 'fake_module.ServiceContainer'}

    runner = ServiceRunner(config=config)
    runner.add_service(TestService1)
    runner.start()

    with pytest.raises(Exception) as exc_info:
        runner.wait()
    assert exc_info.value.args == ('error in container',)
开发者ID:davidszotten,项目名称:nameko,代码行数:27,代码来源:test_service_runner.py

示例3: run_worker

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def run_worker():
    config = get_nameko_config()

    service_runner = ServiceRunner(config)
    service_runner.add_service(RepoWorker)

    service_runner.start()
    service_runner.wait()
开发者ID:jkimbo,项目名称:cinch,代码行数:10,代码来源:nameko_runner.py

示例4: test_config_key

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
    def test_config_key(self, service_cls, container_cls):
        config = {
            'SERVICE_CONTAINER_CLS': "fake_module.ServiceContainerX"
        }
        runner = ServiceRunner(config)
        runner.add_service(service_cls)

        container = get_container(runner, service_cls)
        assert isinstance(container, container_cls)
开发者ID:gwongz,项目名称:nameko,代码行数:11,代码来源:test_service_runner.py

示例5: service_container

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def service_container(patched_db):
    config = {'AMQP_URI': settings.NAMEKO_AMQP_URI}
    runner = ServiceRunner(config)
    runner.add_service(NamekoCollectionService)
    runner.start()

    container = get_container(runner, NamekoCollectionService)
    yield container

    runner.stop()
开发者ID:turc42,项目名称:pylytics,代码行数:12,代码来源:test_nameko.py

示例6: test_runner_lifecycle

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def test_runner_lifecycle(fake_module):
    events = set()

    class Container(object):
        def __init__(self, service_cls, config):
            self.service_name = service_cls.__name__
            self.service_cls = service_cls

        def start(self):
            events.add(('start', self.service_cls.name, self.service_cls))

        def stop(self):
            events.add(('stop', self.service_cls.name, self.service_cls))

        def kill(self):
            events.add(('kill', self.service_cls.name, self.service_cls))

        def wait(self):
            events.add(('wait', self.service_cls.name, self.service_cls))

    fake_module.ServiceContainer = Container

    config = {'SERVICE_CONTAINER_CLS': 'fake_module.ServiceContainer'}
    runner = ServiceRunner(config)

    runner.add_service(TestService1)
    runner.add_service(TestService2)

    runner.start()

    assert events == {
        ('start', 'foobar_1', TestService1),
        ('start', 'foobar_2', TestService2),
    }

    events = set()
    runner.stop()
    assert events == {
        ('stop', 'foobar_1', TestService1),
        ('stop', 'foobar_2', TestService2),
    }

    events = set()
    runner.kill()
    assert events == {
        ('kill', 'foobar_1', TestService1),
        ('kill', 'foobar_2', TestService2),
    }

    events = set()
    runner.wait()
    assert events == {
        ('wait', 'foobar_1', TestService1),
        ('wait', 'foobar_2', TestService2),
    }
开发者ID:davidszotten,项目名称:nameko,代码行数:57,代码来源:test_service_runner.py

示例7: test_runner_lifecycle

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def test_runner_lifecycle():
    events = set()

    class Container(object):
        def __init__(self, service_cls, worker_ctx_cls, config):
            self.service_name = service_cls.__name__
            self.service_cls = service_cls
            self.worker_ctx_cls = worker_ctx_cls

        def start(self):
            events.add(('start', self.service_cls.name, self.service_cls))

        def stop(self):
            events.add(('stop', self.service_cls.name, self.service_cls))

        def kill(self):
            events.add(('kill', self.service_cls.name, self.service_cls))

        def wait(self):
            events.add(('wait', self.service_cls.name, self.service_cls))

    config = {}
    runner = ServiceRunner(config, container_cls=Container)

    runner.add_service(TestService1)
    runner.add_service(TestService2)

    runner.start()

    assert events == {
        ('start', 'foobar_1', TestService1),
        ('start', 'foobar_2', TestService2),
    }

    events = set()
    runner.stop()
    assert events == {
        ('stop', 'foobar_1', TestService1),
        ('stop', 'foobar_2', TestService2),
    }

    events = set()
    runner.kill()
    assert events == {
        ('kill', 'foobar_1', TestService1),
        ('kill', 'foobar_2', TestService2),
    }

    events = set()
    runner.wait()
    assert events == {
        ('wait', 'foobar_1', TestService1),
        ('wait', 'foobar_2', TestService2),
    }
开发者ID:ahmb,项目名称:nameko,代码行数:56,代码来源:test_service_runner.py

示例8: test_kwarg_deprecation_warning

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
    def test_kwarg_deprecation_warning(
        self, warnings, service_cls, container_cls
    ):
        config = {}
        runner = ServiceRunner(config, container_cls=container_cls)
        runner.add_service(service_cls)

        container = get_container(runner, service_cls)
        assert isinstance(container, container_cls)

        # TODO: replace with pytest.warns when eventlet >= 0.19.0 is released
        assert warnings.warn.call_args_list == [call(ANY, DeprecationWarning)]
开发者ID:gwongz,项目名称:nameko,代码行数:14,代码来源:test_service_runner.py

示例9: test_service_integration

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def test_service_integration():
    config = {"AMQP_URI": "amqp://guest:[email protected]:5672/"}
    runner = ServiceRunner(config)
    runner.add_service(ServiceX)
    runner.add_service(ServiceY)
    runner.start()

    container = get_container(runner, ServiceX)

    with entrypoint_hook(container, "remote_method") as entrypoint:
        assert entrypoint("value") == "value-x-y"

    runner.stop()
开发者ID:pombredanne,项目名称:nameko,代码行数:15,代码来源:integration_test.py

示例10: main

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def main():

    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(HelloWorld)
    runner.add_service(FriendlyService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
开发者ID:ahmb,项目名称:nameko,代码行数:15,代码来源:helloworld.py

示例11: main

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def main():
    import logging
    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(MessagingPublisher)
    runner.start()

    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
开发者ID:ahmb,项目名称:nameko,代码行数:15,代码来源:messaging_publisher.py

示例12: main

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def main():
    config_dict = get_config_yaml(CONFIG_YAML_PATH)
    c = update_config_yaml(config_dict, CONFIG_YAML_PATH)
    wus = WatchURLService()
    wus.get_config()
    runner = ServiceRunner(c)
    runner.add_service(WatchURLService)
    # container_a = get_container(runner, WatchURLService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.kill()
    runner.stop()
开发者ID:juga0,项目名称:watch-url,代码行数:16,代码来源:watch_pages_tos_service.py

示例13: test_busy_check_on_teardown

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def test_busy_check_on_teardown():
    # max_workers needs to be provided, as it's used in a semaphore count
    config = {'max_workers': 4}
    kill_called = Mock()

    class MockedContainer(ServiceContainer):
        def kill(self):
            kill_called()
            super(MockedContainer, self).kill()

    sr = ServiceRunner(config, container_cls=MockedContainer)
    sr.add_service(ExampleService)
    sr.start()
    sr.kill()
    with wait_for_call(5, kill_called) as kill_called_waited:
        assert kill_called_waited.call_count == 1
开发者ID:ahmb,项目名称:nameko,代码行数:18,代码来源:test_parallel.py

示例14: main

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
def main():

    logging.basicConfig(level=logging.DEBUG)

    # disable most logging so we can see the console
    logger = logging.getLogger("")
    logger.setLevel(logging.WARNING)

    config = {"AMQP_URI": "amqp://guest:[email protected]:5672/chat"}
    runner = ServiceRunner(config)
    runner.add_service(Chat)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
开发者ID:pbowyer,项目名称:nameko-chat,代码行数:18,代码来源:service.py

示例15: handle

# 需要导入模块: from nameko.runners import ServiceRunner [as 别名]
# 或者: from nameko.runners.ServiceRunner import add_service [as 别名]
    def handle(self, *args, **options):
        runner = ServiceRunner(settings.AMQP_CONFIG)
        runner.add_service(MasterService)

        def shutdown(signum, frame):
            eventlet.spawn_n(runner.kill)
        signal.signal(signal.SIGTERM, shutdown)

        runner.start()
        try:
            runner.wait()
        except KeyboardInterrupt:
            try:
                runner.stop()
            except KeyboardInterrupt:
                runner.kill()
开发者ID:amd77,项目名称:parker,代码行数:18,代码来源:nameko_server_post.py


注:本文中的nameko.runners.ServiceRunner.add_service方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。