优秀的文章

89 阅读1分钟
<?php

/**
 * Created by PhpStorm.
 * User: demo
 * Date: 2021/08/09
 * Time: 下午4:16
 */

namespace Commands\ChainCurrencyData;

use Console\Command;

class ProductionMsgCommand extends Command
{

    protected $cmd = 'production_msg';
    protected $desc = 'update pair lock usd';
    const REDIS_KEY_LAST_PAGE_ID = 'chain_currency_data_last_offset_id';

    /**
     * @throws \Exception
     */
    public function handle()
    {
        $this->info('ProductionMsg Starting.');
        $cache  = \Cache::getInstance();
        $offset = $cache->get(self::REDIS_KEY_LAST_PAGE_ID);
        $offset = $offset != false ? $offset : 0;

        $utc8Hour0Time           = strtotime('00:00:00');
        $mChainCurrencyDataModel = new \ChainCurrencyDataModel();

        while (true) {
            $rawSQL                = "SELECT `market_id`,`contract_address`,`lock_usd`  FROM `chain_currency_data` where theday < " . $utc8Hour0Time . " ORDER BY `lock_usd` DESC  limit " . $offset . ",100";
            $chainCurrencyDataList = $mChainCurrencyDataModel->rawQuery($rawSQL) ?: [];
            if (empty($chainCurrencyDataList)) {
                $this->info("finish all , offset: $offset");
                break;
            }

            $this->info("开始扔kafka");
            $this->info("finish offset: $offset" . " limit 100" . " sql:" . $rawSQL);
            $offset += 100;
            $cache->set(self::REDIS_KEY_LAST_PAGE_ID, $offset);
        }

        $this->info('ProductionMsg Stop.');
    }
}