Пример #1
0
def main():
    load_config()

    handlers = [
        (r"/websocket", ChatHandler),
        (r"/", MainHandler)
    ]
    settings = {
        "debug": True,
        "chat_clients": [],
        "server_id": gen_token(8)
    }

    if options.CLOUDAMQP_URL:
        def broadcast(body):
            for client in settings.get('chat_clients'):
                client.write_message(body)
        queue = PikaTopic(options.CLOUDAMQP_URL,
                          broadcast, 'chat-messages')
        settings['broadcast_queue'] = queue
        logging.info("broadcast_queue %s", options.CLOUDAMQP_URL)
        queue.connect()

    def keep_alive():
        msg = str(time.time()).encode("utf8")
        for client in settings["chat_clients"]:
            client.ping(msg)
    tornado.ioloop.PeriodicCallback(keep_alive, 30000).start()

    application = tornado.web.Application(handlers, **settings)
    application.listen(options.PORT)
    logging.info("listening on port %s", options.PORT)

    tornado.ioloop.IOLoop.current().start()
Пример #2
0
def test_config_env():
    os.environ["db_url"] = "one"
    os.environ["PORT"] = "8081"
    os.environ["CORS_URLS"] = "http://localhost:8888,https://localhost:8843"
    config.load_config()
    assert options["db_url"] == "one"
    assert options["PORT"] == 8081
    assert options["CORS_URLS"] == ['http://localhost:8888',
                                    'https://localhost:8843']
Пример #3
0
def test_config():
    config.load_config()
    assert options["db_url"] == "three"
    assert options["PORT"] == 8080
Пример #4
0
def test_config_file():
    config.load_config(resource_filename("tests", "test.env"))
    assert options["db_url"] == "two"
    assert options["CORS_URLS"] == ['http://localhost:8888',
                                    'https://localhost:8843']
Пример #5
0
def get_db_url():
    config.load_config()
    if options.PORT == 80 and options.db_url == "four":
        os._exit(os.EX_OK)
    else:
        os._exit(os.EX_DATAERR)