コード例 #1
0
def configure(options):
    """
    Find the first app we got command-line options for and setup for it.
    We are only processing one app with this script, so if more than one
    is specified on the command-line, only one of them will get processed.
    No guarantees on which one that is.
    """
    global mongo_db, tmp_dir, max_batch_size, bucket, shard, cycle_time, rebalancing, game, userstate

    game = options.game
    if game is None:
        print "game option is required"
        sys.exit(1)

    ini_file = options.ini
    if ini_file is None:
        print "ini option is required"
        sys.exit(1)

    log.info('Configuring...')
        
    bucket = int(options.bucket)
    shard = int(options.shard)
    max_batch_size = int(options.batch)
    cycle_time = int(options.time)

    from uuss.server import configuration
    (full_config, config) = configuration.init_from_ini(ini_file, [game], {'uuss.use_gevent': False})
    helpers.config = config

    userstate = getattr(model, game).userstate

    tmp_dir = config["%s_user_state.tmp_dir%s" % (game, shard)]
    if not os.path.exists(tmp_dir):
        os.mkdir(tmp_dir)

    rebalancing = converters.asbool(config['%s_user_state.rebalancing' % game]) and options.rebal
    if rebalancing:
        hosts = config['%s_user_state.mongo_hosts_rebal' % game].split(";")
    else:
        hosts = config['%s_user_state.mongo_hosts' % game].split(";")
    mongo_db = mongo.connect(hosts[shard])[config['%s_user_state.mongo_dbname' % game]]