コード例 #1
0
 /**
  *
  */
 public function testReadUserInfo()
 {
     if (extension_loaded('xdebug')) {
         $this->assertTrue(true);
         return;
     }
     $gameVersion = 'tw';
     $pool = PdoFactory::makePool($gameVersion);
     $shardIdList = ShardHelper::listShardId($gameVersion);
     $uidList = [474000, 474001, 474002];
     $userList = [];
     foreach ($shardIdList as $shardId) {
         $pdo = $pool->getByShardId($shardId);
         $generator = CommonInfoProvider::readUserInfo($pdo, $uidList, 1);
         foreach ($generator as $batchUserList) {
             array_walk($batchUserList, function (array $userInfo, $uid) use(&$userList) {
                 $userList[$uid] = $userInfo;
             });
         }
     }
     static::assertEquals($uidList, array_keys($userList));
     foreach ($userList as $user) {
         static::assertTrue(is_array($user));
         static::assertArrayHasKey('uid', $user);
         static::assertArrayHasKey('snsid', $user);
     }
 }
コード例 #2
0
 /**
  *
  */
 public function testFind()
 {
     if (extension_loaded('xdebug')) {
         $this->assertTrue(true);
         return;
     }
     $gameVersion = 'tw';
     $pool = PdoFactory::makePool($gameVersion);
     $uidList = [474000, 474001, 474002];
     $provider = new UserDetailProvider($gameVersion, $pool);
     $payload = array_filter($provider->find($uidList));
     $foundUidList = [];
     foreach ($payload as $shardId => $userList) {
         static::assertStringStartsWith('db', $shardId);
         $foundUidList = array_merge($foundUidList, array_keys($userList));
         foreach ($userList as $user) {
             static::assertTrue(is_array($user));
             static::assertArrayHasKey('uid', $user);
             static::assertArrayHasKey('snsid', $user);
             static::assertArrayHasKey('history_pay_amount', $user);
         }
     }
     sort($uidList);
     sort($foundUidList);
     static::assertEquals($uidList, $foundUidList);
 }
コード例 #3
0
 /**
  *
  */
 public function testFactory()
 {
     if (extension_loaded('xdebug')) {
         $this->assertTrue(true);
         return;
     }
     $pdo = PdoFactory::makeGlobalPdo('tw');
     static::assertInstanceOf(\PDO::class, $pdo);
 }
コード例 #4
0
 /**
  * SyncMachine constructor.
  *
  * @param string $gameVersion
  * @param string $esHost
  */
 public function __construct($gameVersion, $esHost)
 {
     $this->gameVersion = $gameVersion;
     $this->esHost = $esHost;
     $date = date('Ymd');
     $persist = new AggregatorPersist(LOG_DIR . '/' . $gameVersion . '.uid.persist');
     $this->aggregator = new UidAggregator($persist);
     $this->shardList = ShardHelper::listShardId($gameVersion);
     $this->logFile = LOG_DIR . '/' . $date . '/' . $gameVersion . '.machine';
     $this->prepareLogDir($this->logFile);
     $this->dataProvider = new UserDetailProvider($gameVersion, PdoFactory::makePool($gameVersion));
     $this->indexer = IndexerFactory::make($esHost, $gameVersion, self::FLUSH_MAGIC_NUMBER);
 }
コード例 #5
0
 /**
  *
  */
 public function test()
 {
     if (extension_loaded('xdebug')) {
         $this->assertTrue(true);
         return;
     }
     $gameVersion = 'tw';
     $pool = PdoFactory::makePool($gameVersion);
     $provider = new InstallUidProvider($gameVersion, $pool);
     $groupedUidList = array_filter($provider->generate(date('Y-m-d')));
     foreach ($groupedUidList as $shardId => $uidList) {
         static::assertStringStartsWith('db', $shardId);
         static::assertTrue(is_array($uidList));
         static::assertEquals(range(0, count($uidList) - 1), array_keys($uidList));
     }
 }
コード例 #6
0
 /**
  *
  */
 public function testReadUserInfo()
 {
     if (extension_loaded('xdebug')) {
         $this->assertTrue(true);
         return;
     }
     $gameVersion = 'tw';
     $pdo = PdoFactory::makeGlobalPdo($gameVersion);
     $snsidUidPairs = ['100001349218797' => 474000, '100001109305149' => 237204];
     $uidSnsidPairs = array_flip($snsidUidPairs);
     $userList = PaymentInfoProvider::readUserInfo($pdo, $snsidUidPairs, 1);
     //        dump($userList);
     foreach ($userList as $uid => $digest) {
         static::assertInstanceOf(PaymentDigest::class, $digest);
         static::assertEquals($uid, $digest->uid);
         $snsid = $uidSnsidPairs[$uid];
         static::assertEquals($snsid, $digest->snsid);
         static::assertTrue(is_int($digest->lastPayTime));
         static::assertTrue(is_float($digest->lastPayAmount));
         static::assertTrue(is_float($digest->historyPayAmount));
     }
 }
コード例 #7
0
    if (!is_dir($dir)) {
        mkdir($dir, 0755, true);
    }
    return $filePath;
};
$fromDate = date_create_from_format('Ymd', $fromDay);
if (!$fromDate instanceof \DateTime) {
    appendLog(sprintf('from [%s] not valid', $fromDay));
    return;
}
$toDate = date_create_from_format('Ymd', $toDay);
if (!$toDate instanceof \DateTime) {
    appendLog(sprintf('to [%s] not valid', $toDay));
    return;
}
$pdoPool = PdoFactory::makePool($gameVersion);
$installUidProvider = new InstallUidProvider($gameVersion, $pdoPool);
$userDetailProvider = new UserDetailProvider($gameVersion, $pdoPool);
$magicNumber = isset($options['magic']) ? (int) $options['magic'] : 500;
assert($magicNumber > 10);
$indexer = IndexerFactory::make(ELASTIC_SEARCH_HOST, $gameVersion, $magicNumber);
if ($verbose) {
    dump(sprintf('version: %s, from: %s, to: %s, safe: %d, magic: %d', $gameVersion, $fromDay, $toDay, $safeRound, $magicNumber));
}
$calendarDayGenerator = CalendarDayGenerator::generate($fromDate->getTimestamp(), $toDate->getTimestamp());
$totalUser = 0;
$processedRound = 0;
foreach ($calendarDayGenerator as $calendarDay) {
    $markerDate = new DateTimeImmutable($calendarDay);
    if ($calendarMarker->isMarked($markerDate)) {
        appendLog('bypass ' . $markerDate->format('Y-m-d'));
コード例 #8
0
ファイル: pdo.php プロジェクト: jiangyu7408/notification
            if ($name === 'PDO::ATTR_CONNECTION_STATUS') {
                $value = call_user_func($connectionStatusParser, $value);
            }
        } catch (PDOException $e) {
            $value = 'not supported';
            $errMsg = $e->getMessage();
            if (strpos($errMsg, 'not support') === false) {
                $value .= '' . $errMsg;
            }
        }
        $info[$name] = $value;
    }
    return $info;
};
$pdoOptionChecker = function (PDO $pdo) use($optionsReader) {
    $attributes = ['SERVER_INFO', 'CONNECTION_STATUS'];
    return call_user_func($optionsReader, $pdo, $attributes);
};
$option = getopt('', ['gv:']);
$gameVersion = isset($option['gv']) ? trim($option['gv']) : 'tw';
$shardConfigList = \Database\ShardHelper::shardConfigGenerator($gameVersion);
$infoList = [];
foreach ($shardConfigList as $option) {
    $pdo = \Database\PdoFactory::makePool($gameVersion)->getByOption($option);
    if ($pdo === false) {
        dump('error on ' . json_encode($option));
        continue;
    }
    $infoList[$option['shardId']] = call_user_func($pdoOptionChecker, $pdo);
}
dump($infoList);
コード例 #9
0
 /**
  * @param array $userList
  *
  * @return array
  */
 protected function appendPaymentDigest(array $userList)
 {
     $snsidUidPairs = [];
     foreach ($userList as $uid => $userInfo) {
         assert((int) $uid === (int) $userInfo['uid']);
         $snsidUidPairs[$userInfo['snsid']] = $userInfo['uid'];
     }
     $paymentDigestList = PaymentInfoProvider::readUserInfo(PdoFactory::makeGlobalPdo($this->gameVersion), $snsidUidPairs);
     $emptyPaymentDigest = new PaymentDigest();
     $dataSet = [];
     foreach ($userList as $uid => $userInfo) {
         $paymentDigest = isset($paymentDigestList[$uid]) ? $paymentDigestList[$uid] : $emptyPaymentDigest;
         $dataSet[$uid] = array_merge($userInfo, $this->injectPaymentDigest($paymentDigest));
     }
     return $dataSet;
 }
コード例 #10
0
$quitTimestamp = $now + $round * $interval;
if ($verbose) {
    $msg = sprintf('game version: %s, specifiedDate=%s, interval=%d, round=%d, start at: %s, quit at: %s', $gameVersion, $specifiedDate, $interval, $round, date('H:i:s'), date('H:i:s', $quitTimestamp));
    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();
コード例 #11
0
    $gameVersion = GAME_VERSION;
} else {
    assert(isset($options['gv']), 'game version not defined');
    $gameVersion = trim($options['gv']);
}
$interval = isset($options['interval']) ? $options['interval'] : 20;
$backStep = isset($options['bs']) ? $options['bs'] : $interval;
$round = isset($options['round']) ? $options['round'] : 100;
$lastActiveTimestamp = time() - $backStep;
$quitTimestamp = time() + $round * $interval;
if ($verbose) {
    $msg = sprintf('game version: %s, backStep=%d, interval=%d, round=%d, start at: %s, quit at: %s', $gameVersion, $backStep, $interval, $round, date('H:i:s', $lastActiveTimestamp), date('H:i:s', $quitTimestamp));
    dump($msg);
}
$myself = basename(__FILE__);
$uidProvider = new ActiveUidProvider($gameVersion, \Database\PdoFactory::makePool($gameVersion));
$shardList = ShardHelper::listShardId($gameVersion);
$queue = new UidQueue(UID_QUEUE_DIR, $gameVersion, $shardList);
$stepGenerator = WorkRoundGenerator::generate($lastActiveTimestamp, $quitTimestamp, $interval, $verbose);
foreach ($stepGenerator as $timestamp) {
    $msg = $myself . ': ' . date('c', $timestamp) . ' run with ts ' . date('c', $timestamp);
    appendLog($msg);
    $groupedUidList = $uidProvider->generate($lastActiveTimestamp);
    $deltaList = $uidProvider->getDeltaList();
    $totalCount = 0;
    foreach ($groupedUidList as $shardId => $shardUidList) {
        $shardCount = count($shardUidList);
        if ($shardCount === 0) {
            continue;
        }
        $verbose && appendLog(sprintf('%s: %s found %d active user, cost %s', $myself, $shardId, $shardCount, PHP_Timer::secondsToTimeString($deltaList[$shardId])));
コード例 #12
0
ファイル: updateES.php プロジェクト: jiangyu7408/notification
require __DIR__ . '/../../bootstrap.php';
$options = getopt('v', ['gv:', 'es:', 'uid:']);
$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';
assert(isset($options['uid']), 'uid not defined');
$uid = trim($options['uid']);
$msg = sprintf('game version: %s, ES host: %s, uid: %s', $gameVersion, $esHost, $uid);
$verbose && dump($msg);
$provider = new UserDetailProvider($gameVersion, PdoFactory::makePool($gameVersion));
$groupedUserList = array_filter($provider->find([$uid]));
if ($verbose) {
    dump(__FILE__);
    dump($groupedUserList);
}
$indexer = IndexerFactory::make($esHost, $gameVersion);
foreach ($groupedUserList as $shardId => $shardUserList) {
    $delta = $indexer->batchUpdate($shardUserList);
    $batchResult = $indexer->getBatchResult();
    dump(__FILE__);
    array_map(function ($errorString) {
        $decoded = json_decode($errorString, true);
        if (is_array($decoded)) {
            dump($decoded);
        } else {