package com.gh.common import com.gh.common.exposure.ExposureManager import com.gh.common.filter.RegionSettingHelper import com.gh.common.loghub.LoghubUtils import com.gh.common.util.doOnMainProcessOnly import com.gh.common.util.tryCatchInRelease import com.gh.common.videolog.VideoRecordUtils import com.gh.download.DownloadDataHelper import com.gh.gamecenter.entity.TimeEntity import com.gh.gamecenter.retrofit.Response import com.gh.gamecenter.retrofit.RetrofitManager import com.halo.assistant.HaloApp import io.reactivex.schedulers.Schedulers import kotlin.concurrent.fixedRateTimer object FixedRateJobHelper { private const val CHECKER_PERIOD: Long = 15 * 1000L private const val TIME_PERIOD: Long = 600 * 1000L private const val LOGHUB_PERIOD: Long = 120 * 1000L private const val EXPOSURE_PERIOD: Long = 300 * 1000L private const val REGION_SETTING_PERIOD: Long = 300 * 1000L private const val VIDEO_RECORD_PERIOD: Long = 60 * 1000L private const val DOWNLOAD_HEARTBEAT_PERIOD: Long = 60 * 1000L private const val DOWNLOAD_HEARTBEAT_SHEET_PERIOD: Long = 15 * 1000L private var mExecuteCount: Int = 0 var timeDeltaBetweenServerAndClient: Long = 0 @JvmStatic fun begin() { doOnMainProcessOnly { fixedRateTimer("Global-Fixed-Rate-Timer", initialDelay = 100, period = CHECKER_PERIOD) { // 时间校对,10分钟一次 if ((mExecuteCount * CHECKER_PERIOD) % TIME_PERIOD == 0L) { RetrofitManager.getInstance().api.time .subscribeOn(Schedulers.io()) .subscribe(object : Response() { override fun onResponse(response: TimeEntity?) { val serverTime = response?.time serverTime?.let { timeDeltaBetweenServerAndClient = it * 1000 - System.currentTimeMillis() } } }) } // 提交曝光数据 if ((mExecuteCount * CHECKER_PERIOD) % EXPOSURE_PERIOD == 0L) { ExposureManager.commitSavedExposureEvents(true) } // 分片检测下载进度 if ((mExecuteCount * CHECKER_PERIOD) % DOWNLOAD_HEARTBEAT_SHEET_PERIOD == 0L) { tryCatchInRelease { val upload = (mExecuteCount * CHECKER_PERIOD) % DOWNLOAD_HEARTBEAT_PERIOD == 0L DownloadDataHelper.uploadDownloadHeartbeat(upload) } } // 提交普通 loghub 数据 if ((mExecuteCount * CHECKER_PERIOD) % LOGHUB_PERIOD == 0L) { LoghubUtils.commitSavedLoghubEvents() } // 更新游戏屏蔽信息 if ((mExecuteCount * CHECKER_PERIOD) % REGION_SETTING_PERIOD == 0L) { if (HaloApp.getInstance().isRunningForeground) { RegionSettingHelper.getRegionSetting() } } // 提交视频浏览记录数据 if ((mExecuteCount * CHECKER_PERIOD) % VIDEO_RECORD_PERIOD == 0L) { VideoRecordUtils.commitVideoRecord() } // ExposureUtils.logADownloadCompleteExposureEvent(GameEntity(id = mExecuteCount.toString(), name = "测试曝光上传"), platform = "", trace = null, downloadType = ExposureUtils.DownloadType.DOWNLOAD) mExecuteCount++ } } } }