• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python runners.ServiceRunner类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_config_key

    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,代码行数:9,代码来源:test_service_runner.py


示例2: main

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,代码行数:26,代码来源:database_service.py


示例3: test_kwarg_deprecation_warning

    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,代码行数:12,代码来源:test_service_runner.py


示例4: main

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,代码行数:13,代码来源:messaging_publisher.py


示例5: test_runner_waits_raises_error

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,代码行数:25,代码来源:test_service_runner.py


示例6: run_worker

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,代码行数:8,代码来源:nameko_runner.py


示例7: main

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,代码行数:16,代码来源:service.py


示例8: service_container

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,代码行数:10,代码来源:test_nameko.py


示例9: run

def run(services, config, backdoor_port=None):
    service_runner = ServiceRunner(config)
    for service_cls in services:
        service_runner.add_service(service_cls)

    def shutdown(signum, frame):
        # signal handlers are run by the MAINLOOP and cannot use eventlet
        # primitives, so we have to call `stop` in a greenlet
        eventlet.spawn_n(service_runner.stop)

    signal.signal(signal.SIGTERM, shutdown)

    if backdoor_port is not None:
        setup_backdoor(service_runner, backdoor_port)

    service_runner.start()

    # if the signal handler fires while eventlet is waiting on a socket,
    # the __main__ greenlet gets an OSError(4) "Interrupted system call".
    # This is a side-effect of the eventlet hub mechanism. To protect nameko
    # from seeing the exception, we wrap the runner.wait call in a greenlet
    # spawned here, so that we can catch (and silence) the exception.
    runnlet = eventlet.spawn(service_runner.wait)

    while True:
        try:
            runnlet.wait()
        except OSError as exc:
            if exc.errno == errno.EINTR:
                # this is the OSError(4) caused by the signalhandler.
                # ignore and go back to waiting on the runner
                continue
            raise
        except KeyboardInterrupt:
            print()  # looks nicer with the ^C e.g. bash prints in the terminal
            try:
                service_runner.stop()
            except KeyboardInterrupt:
                print()  # as above
                service_runner.kill()
        else:
            # runner.wait completed
            break
开发者ID:sohonetlabs,项目名称:nameko,代码行数:43,代码来源:run.py


示例10: test_service_integration

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,代码行数:13,代码来源:integration_test.py


示例11: test_busy_check_on_teardown

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,代码行数:16,代码来源:test_parallel.py


示例12: test_busy_check_on_teardown

def test_busy_check_on_teardown():
    # max_workers needs to be provided, as it's used in a semaphore count
    config = MagicMock({'max_workers': 4})
    kill_called = Mock()

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

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


示例13: test_service_x_y_integration

def test_service_x_y_integration():

    # run services in the normal manner
    config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(ServiceX)
    runner.add_service(ServiceY)
    runner.start()

    # artificially fire the "remote_method" entrypoint on ServiceX
    # and verify response
    container = get_container(runner, ServiceX)
    with entrypoint_hook(container, "remote_method") as entrypoint:
        assert entrypoint("value") == "value-x-y"

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


示例14: test_mail_service_integration

    def test_mail_service_integration(self):
        config = {'AMQP_URI': 'amqp://guest:[email protected]:5672/'}
        runner = ServiceRunner(config)
        runner.add_service(PaymentService)
        runner.add_service(MailService)


        payment_container = get_container(runner, PaymentService)
        mail_container = get_container(runner, MailService)

        # turns off timer event
        # restrict_entrypoints(payment_container, *[])

        runner.start()

        with entrypoint_hook(payment_container, 'emit_event') as entrypoint:
            with entrypoint_waiter(mail_container, 'on_payment_received'):
                entrypoint()

        assert True
开发者ID:gyk,项目名称:nameko-mailer,代码行数:20,代码来源:test_mail_service.py


示例15: test_runner_waits_raises_error

def test_runner_waits_raises_error():
    class Container(object):
        def __init__(self, service_cls, worker_ctx_cls, config):
            pass

        def start(self):
            pass

        def stop(self):
            pass

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

    runner = ServiceRunner(config={}, container_cls=Container)
    runner.add_service(TestService1)
    runner.start()

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


示例16: run

def run():
    config = {'AMQP_URI': 'amqp://localhost'}
    runner = ServiceRunner(config)
    runner.add_service(AlarmService)
    runner.add_service(HttpEntrypointService)
    runner.add_service(LightService)
    runner.add_service(LocalStorageService)
    runner.add_service(SpotifyService)
    runner.add_service(VolumeService)
    runner.start()

    runnlet = eventlet.spawn(runner.wait)

    try:
        runnlet.wait()
    except KeyboardInterrupt:
        try:
            runner.stop()
        except KeyboardInterrupt:
            runner.kill()
开发者ID:miguelfrde,项目名称:roomcontrol_backend,代码行数:20,代码来源:roomcontrol.py


示例17: make_runner

 def make_runner(*service_classes):
     runner = ServiceRunner(rabbit_config)
     for service_cls in service_classes:
         runner.add_service(service_cls)
     all_runners.append(runner)
     return runner
开发者ID:ahmb,项目名称:nameko,代码行数:6,代码来源:large_integration_test.py


示例18: handle

    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,代码行数:16,代码来源:nameko_server_post.py


示例19: main

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,代码行数:13,代码来源:helloworld.py


示例20: ServiceA

from nameko.runners import ServiceRunner
from nameko.utils import get_container


class ServiceA(object):
    name = "service_a"


class ServiceB(object):
    name = "service_b"


# create a runner for ServiceA and ServiceB
runner = ServiceRunner(config={})
runner.add_service(ServiceA)
runner.add_service(ServiceB)

# ``get_container`` will return the container for a particular service
container_a = get_container(runner, ServiceA)

# start both services
runner.start()

# stop both services
runner.stop()
开发者ID:mamachanko,项目名称:nameko,代码行数:25,代码来源:service_runner.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python events.event_dispatcher函数代码示例发布时间:2022-05-27
下一篇:
Python main.setup_parser函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap