fix(bugcollect): 平台配置下发后延迟重试 flush,修复事件丢失
- startCrashCapture 后延迟检查 bugCollectApiUrl,就绪后再次 flush - 添加调试日志帮助排查上传流程
这个提交包含在:
父节点
ceaaeca1fe
当前提交
3f03f5c1de
@ -5,6 +5,12 @@ import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.os.Build
|
||||
import com.xuqm.sdk.XuqmSDK
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.LinkedList
|
||||
|
||||
object BugCollect {
|
||||
@ -82,10 +88,12 @@ object BugCollect {
|
||||
)
|
||||
if (!isReady()) {
|
||||
synchronized(pendingErrorsLock) { pendingErrors.add(event) }
|
||||
android.util.Log.d("BugCollect", "captureError: SDK not ready, queued (${pendingErrors.size} pending)")
|
||||
return
|
||||
}
|
||||
flushPendingErrors()
|
||||
queue().push(event)
|
||||
android.util.Log.d("BugCollect", "captureError: pushed to queue")
|
||||
}
|
||||
|
||||
fun captureCrash(error: Throwable, tags: Map<String, Any?> = emptyMap()) {
|
||||
@ -153,6 +161,17 @@ object BugCollect {
|
||||
)
|
||||
flushPendingErrors()
|
||||
queue().uploadPendingCrashes()
|
||||
// 平台配置可能在初始化之后才下发,延迟重试 flush
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
for (i in 1..10) {
|
||||
delay(2000)
|
||||
if (!XuqmSDK.bugCollectApiUrl.isNullOrBlank()) {
|
||||
flushPendingErrors()
|
||||
queue().uploadPendingCrashes()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 将 SDK 未就绪时暂存的错误事件 flush 到队列。 */
|
||||
@ -163,6 +182,7 @@ object BugCollect {
|
||||
pendingErrors.clear()
|
||||
list
|
||||
}
|
||||
android.util.Log.d("BugCollect", "flushPendingErrors: ${events.size} events")
|
||||
events.forEach { queue().push(it) }
|
||||
}
|
||||
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户