Exemplo n.º 1
0
function main($server_cfg)
{
    $options = get_options();
    if (isset($options['g']) && $options['g'] !== '') {
        $game_names = explode(",", $options['g']);
    } else {
        $game_names = $server_cfg['game_list'];
    }
    $time_slots = null;
    if (!empty($options['t'])) {
        $time_slots = $options['t'];
    }
    $timestamp = $_SERVER['REQUEST_TIME'];
    $current_time_slot = (int) ($timestamp / (30 * 60));
    foreach ($game_names as $game_name) {
        zpm_preamble($game_name);
        // MODIFIED!!!! Create and mount next two timeslots !!!
        $game_cfg = load_game_config($game_name);
        if (!$game_cfg) {
            error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            continue;
        }
        $target_dir = sprintf($server_cfg['root_upload_directory'], $game_cfg["name"]);
        $target_dir = $target_dir . "/%s/" . $server_cfg["profile_upload_directory"];
        $dir_name_array = create_directory($target_dir, $current_time_slot, $server_cfg, $game_cfg);
        if ($dir_name_array === null) {
            error_log("Directory creation failed for the game " . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            continue;
        }
        if ($dir_name_array === 0) {
            error_log("No Ram disk Exist!!!" . $game_cfg['name'], 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
        }
        //creating new games and getting the list of web arrays to process data for
        $rs = new RightScale($server_cfg, load_game_config($game_name));
        $rs->make_array_games();
        $array_ids = $rs->get_arrays_to_serve();
        //
        // Wrap processing for each game inside a file lock
        //
        $game_lock_file = sprintf($server_cfg["zperfmon_lock_file"], $game_name);
        $game_lock_handle = grab_lock($game_lock_file, $server_cfg, $game_cfg);
        if (!$game_lock_handle) {
            error_log("Could not get exclusive lock for \"{$game_name}\"\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg);
            continue;
        }
        //processing parent game
        try {
            //
            // process uploaded data
            //
            run_cron_for_game($server_cfg, $game_cfg, $time_slots);
        } catch (Exception $e) {
            error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
        }
        // loop to process data for each web array
        foreach ($array_ids as $array) {
            try {
                $game_cfg = load_game_config($game_name, $array);
                if (!$game_cfg) {
                    error_log("configuration for " . $game_name . " is not loaded\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
                    continue;
                }
                //
                // process uploaded data
                //
                run_cron_for_game($server_cfg, $game_cfg, $time_slots);
            } catch (Exception $e) {
                error_log("Upload processing for {$game_name} failed\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
                error_log("Exception says: " . $e->getMessage() . "\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
            }
        }
        // compress for parent game
        // This implementation forces us to always pass a timeslot
        // while calling this script. otherwise compression will fail.
        $game_cfg = load_game_config($game_name);
        compress_unziped_profiles($server_cfg, $game_cfg, $time_slots);
        // Now compress the array games
        foreach ($array_ids as $array) {
            $game_cfg = load_game_config($game_name, $array);
            compress_unziped_profiles($server_cfg, $game_cfg, $time_slots);
        }
        // cleanup the lock
        drop_lock($game_lock_handle, $game_lock_file);
        zpm_postamble($game_name);
        //MODIFIED!!!!
        if ($dir_name_array != 0) {
            delete_ramdisk_data($game_name, $time_slots, $timestamp, $server_cfg, $game_cfg);
        }
    }
}
Exemplo n.º 2
0
function run_upload_processing($server_cfg)
{
    date_default_timezone_set('UTC');
    $current_timestamp = $_SERVER['REQUEST_TIME'];
    $options = getopt("g:t:a");
    if (isset($options['g']) && $options['g'] !== '') {
        $game_names = explode(",", $options['g']);
    } else {
        $game_names = $server_cfg['game_list'];
    }
    $time_slots = null;
    if (empty($options['t'])) {
        $time_slots = (int) ($current_timestamp / 1800);
        $time_slots = "{" . $time_slots . "}";
    } else {
        $time_slots = $options['t'];
    }
    foreach ($game_names as $game_name) {
        zpm_preamble($game_name);
        $game_cfg = load_game_config($game_name);
        // Process each array of the game
        $rsObj = new RightScale($server_cfg, $game_cfg);
        $rsObj->make_array_games();
        process_uploads($server_cfg, $game_cfg, $time_slots, $rsObj);
        zpm_postamble($game_name);
    }
}