示例#1
0
def main():
    logs.init_logging()

    # TODO: Support multiple agents with ability to initiate threads.
    # dispatch = agents.Dispatch([
    #   agents.PersonalizedAgent({
    #     '*****@*****.**': 'First Name',
    #   }),
    #   agents.SimpleReplyAgent('Sorry, I do not recognize you.'),
    # ])

    example_agents = [agents.LoggingAgent()]
    dispatch = agents.Dispatch(example_agents)
    account = accounts.Account.from_config(config)
    server = servers.Server(account, dispatch, refresh_s=10.0)

    while True:
        _LOG.info('Starting server with account %s, refresh_s=10.0',
                  account.username)
        try:
            server.start()
        except servers.FatalError as e:
            _LOG.exception(e)
            sys.exit(1)
        except Exception as e:
            _LOG.exception('Server exiting with error: %s', e)
        time.sleep(10)
示例#2
0
def main():
    parser = argparse.ArgumentParser(
        description='Serve the Minefield Mahjong application.')
    parser.add_argument('--host', metavar='IP', type=str, default='127.0.0.1')
    parser.add_argument('--port', metavar='PORT', type=int, default=8080)
    parser.add_argument('--debug',
                        action='store_true',
                        default=False,
                        help='Debug mode (serve static files as well)')
    args = parser.parse_args()

    init_logging()

    print 'Starting server:', args
    fname = os.path.join(os.path.dirname(__file__), 'minefield.db')
    server = GameServer(fname, use_bots=True)

    def shutdown():
        server.stop(immediate=True)
        sys.exit(signal.SIGINT)

    gevent.signal(signal.SIGINT, shutdown)
    server.serve(args.host, args.port, args.debug)
示例#3
0
import sys

from tornado.ioloop import IOLoop
from referee import Referee

from logs import init_logging

if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_connection_id = sys.argv[3]
    docker_id = sys.argv[4]
    try:
        log_level = int(sys.argv[5])
    except IndexError:
        init_logging(logging.INFO)
    else:
        init_logging(log_level, config={'root': {
            'handlers': ['console'],
        }})

    logger = logging.getLogger()
    logger.info("START Host:{} PORT:{} CONNECTION_ID:{} DOCKER_ID:{}".format(
        host, port, user_connection_id, docker_id))

    def handle_signal(sig, frame):
        IOLoop.instance().add_callback(IOLoop.instance().stop)

    signal.signal(signal.SIGINT, handle_signal)
    signal.signal(signal.SIGTERM, handle_signal)
示例#4
0
from tornado.ioloop import IOLoop
from referee import Referee

from logs import init_logging


if __name__ == "__main__":
    host = sys.argv[1]
    port = int(sys.argv[2])
    user_connection_id = sys.argv[3]
    docker_id = sys.argv[4]
    try:
        log_level = int(sys.argv[5])
    except IndexError:
        init_logging(logging.INFO)
    else:
        init_logging(log_level, config={
            'root': {
                'handlers': ['console'],
            }
        })

    logger = logging.getLogger()
    logger.info("START Host:{} PORT:{} CONNECTION_ID:{} DOCKER_ID:{}".format(
        host, port, user_connection_id, docker_id))

    def handle_signal(sig, frame):
        IOLoop.instance().add_callback(IOLoop.instance().stop)
    signal.signal(signal.SIGINT, handle_signal)
    signal.signal(signal.SIGTERM, handle_signal)