Ejemplo n.º 1
0
});
$options = getopt('v', ['gv:', 'es:', 'bs:', 'interval:', 'round:', 'repeatTimes:', 'waitTime:']);
$verbose = isset($options['v']);
$gameVersion = null;
if (defined('GAME_VERSION')) {
    $gameVersion = GAME_VERSION;
} else {
    assert(isset($options['gv']), 'game version not defined');
    $gameVersion = trim($options['gv']);
}
$esHost = isset($options['es']) ? $options['es'] : '52.19.73.190';
$backStep = isset($options['bs']) ? $options['bs'] : 1;
$interval = isset($options['interval']) ? $options['interval'] : 20;
$round = isset($options['round']) ? $options['round'] : 100;
$maxRepeatTimes = isset($options['repeatTimes']) ? $options['repeatTimes'] : 100;
$longestWaitTime = isset($options['waitTime']) ? $options['waitTime'] : 10 * 60;
$lastActiveTimestamp = time() - $backStep;
$quitTimestamp = time() + $round * $interval;
if ($verbose) {
    $msg = sprintf('game version: %s, ES host: %s, backStep=%d, interval=%d, round=%d, start at: %s, quit at: %s', $gameVersion, $esHost, $backStep, $interval, $round, date('H:i:s', $lastActiveTimestamp), date('H:i:s', $quitTimestamp));
    dump($msg);
    dump(sprintf('max repeat times: %d, max wait time: %d', $maxRepeatTimes, $longestWaitTime));
}
$myself = basename(__FILE__);
$stepGenerator = WorkRoundGenerator::generate($lastActiveTimestamp, $quitTimestamp, $interval, $verbose);
foreach ($stepGenerator as $timestamp) {
    $msg = $myself . ': ' . date('c', $timestamp) . ' run with ts ' . $timestamp;
    dump($msg);
    appendLog($msg);
    (new SyncMachine($gameVersion, $esHost))->run($maxRepeatTimes, $longestWaitTime);
}
Ejemplo n.º 2
0
    dump($msg);
}
$logFileGetter = function ($gameVersion, $date) {
    $logDate = str_replace('-', '', $date);
    $filePath = LOG_DIR . '/' . $logDate . '/' . $gameVersion . '.install';
    $dir = dirname($filePath);
    if (!is_dir($dir)) {
        mkdir($dir, 0755, true);
    }
    return $filePath;
};
$myself = basename(__FILE__);
$installUidProvider = new InstallUidProvider($gameVersion, PdoFactory::makePool($gameVersion));
$shardList = ShardHelper::listShardId($gameVersion);
$queue = new UidQueue(UID_QUEUE_DIR, $gameVersion, $shardList);
$stepGenerator = WorkRoundGenerator::generate($now, $quitTimestamp, $interval, false);
foreach ($stepGenerator as $timestamp) {
    $msg = $myself . ': ' . date('c', $timestamp) . ' run with ts ' . date('c', $timestamp);
    appendLog($msg);
    $date = $specifiedDate ? $specifiedDate : date('Y-m-d');
    $groupedUidList = $installUidProvider->generate($date, function ($shardId, $userCount, $delta) {
        if ($userCount === 0) {
            return;
        }
        appendLog(sprintf('%s install(%d) cost %s', $shardId, $userCount, PHP_Timer::secondsToTimeString($delta)));
    });
    $queue->push($groupedUidList);
    $deltaList = $installUidProvider->getDeltaList();
    $totalCount = 0;
    foreach ($groupedUidList as $shardId => $shardUidList) {
        $shardCount = count($shardUidList);