示例#1
0
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', )
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',)
示例#3
0
def run_worker():
    config = get_nameko_config()

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

    service_runner.start()
    service_runner.wait()
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),
    }
示例#5
0
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),
    }
示例#6
0
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),
    }
示例#7
0
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),
    }
def main():
    config_dict = get_config_yaml(CONFIG_YAML_PATH)
    c = update_config_yaml(config_dict, CONFIG_YAML_PATH)
    runner = ServiceRunner(c)
    runner.add_service(FetchURLService)
    # container_a = get_container(runner, FetchURLService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.kill()
    runner.stop()
示例#9
0
文件: helloworld.py 项目: ahmb/nameko
def main():

    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://*****:*****@localhost:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(HelloWorld)
    runner.add_service(FriendlyService)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
示例#10
0
def main():
    import logging
    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://*****:*****@localhost:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(MessagingPublisher)
    runner.start()

    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
示例#11
0
def main():
    import logging
    logging.basicConfig(level=logging.DEBUG)

    config = {'AMQP_URI': 'amqp://*****:*****@localhost:5672/'}
    runner = ServiceRunner(config)
    runner.add_service(AdderService)
    runner.start()

    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
示例#12
0
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()
示例#13
0
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://*****:*****@localhost:5672/chat'}
    runner = ServiceRunner(config)
    runner.add_service(Chat)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
示例#14
0
    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()
示例#15
0
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://*****:*****@localhost:5672/chat"}
    runner = ServiceRunner(config)
    runner.add_service(Chat)
    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.stop()
示例#16
0
    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()
示例#17
0
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', )
示例#18
0
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',)
def run_all():
    services = {}
    for f in root.iterdir():
        if f.is_dir() and f.name.endswith("Service") and f.name.startswith(
                "Admin"):
            name = f.name
            service = importlib.import_module(name + '.service')
            services[name] = service
    from nameko.runners import ServiceRunner

    runner = ServiceRunner(config={"AMQP_URI": "amqp://*****:*****@ip"})
    for name, service in services.items():
        cls = getattr(service, name)
        print(name, service, cls)
        runner.add_service(cls)

    print('wsadsa')

    runner.start()
    try:
        runner.wait()
    except KeyboardInterrupt:
        runner.kill()
        runner.stop()
示例#20
0
def run_all():
    '''
    启动所有服务
    '''
    try:
        services = {}
        for f in root.iterdir():
            if f.is_dir() and f.name.endswith('Service'):
                name = f.name
                service = importlib.import_module(name + '.service')
                services[name] = service
        from nameko.runners import ServiceRunner

        runner = ServiceRunner(
            config={'AMQP_URI': 'amqp://*****:*****@192.168.2.215'})
        for name, service in services.items():
            cls = getattr(service, name)
            runner.add_service(cls)

        runner.start()
        runner.wait()
        # runner.stop()
    except Exception as e:
        runner.kill()
示例#21
0
    buf = BufferB()
    T = 1

    @timer(interval=T)  # how to use a value from constructor?
    def send(self):
        if self.buf["at0"] == 0:
            self.buf["at0"] = datetime.strptime(self.microA_rpc.get_t0(),
                                                "%Y-%m-%d %H:%M:%S.%f")

        self.buf["value"] += self.buf["S"] * self.buf["F"]
        key = str(datetime.now() - self.buf["time"])
        self.microA_rpc.put(key, self.buf["value"])

        print self.buf['at0']


if __name__ == '__main__':
    config = {'AMQP_URI': "amqp://*****:*****@localhost"}
    print "inside run_services"
    # with run_services(config, MicroB) as runner:
    #     runner.start()
    #     runner.wait()
    #     runner.stop()

    runner = ServiceRunner(config=config)
    runner.add_service(MicroB)

    runner.start()
    runner.wait()
    runner.stop()