Exemplo n.º 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()
Exemplo n.º 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']
Exemplo n.º 3
0
def test_config():
    config.load_config()
    assert options["db_url"] == "three"
    assert options["PORT"] == 8080
Exemplo n.º 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']
Exemplo n.º 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)