微信审核回调改为先落库后应答并异步探测补偿
自动发布开发环境 Nacos 配置 / publish (push) Successful in 24s
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 8s

- 回调到达即持久化解密报文与 trace_id,落库失败返回 500 让微信重试
- 异步执行器按环境顺序探测认领,状态机 PENDING/PROCESSING/SUCCESS/NO_ENV/FAILED/DEAD
- 定时补偿按 30/120/600/3600 秒退避,达到上限置 DEAD 并告警,启动时恢复未完成任务
- 数据库条件更新抢锁保证多实例只处理一次,新增 V22 迁移与管理端重试配置/明细
This commit is contained in:
2026-11-07 13:02:26 +08:00
parent 69a32672c9
commit e870285300
14 changed files with 798 additions and 310 deletions
+8 -1
View File
@@ -1598,6 +1598,8 @@ export interface SecureIntegrationConfigVO {
moderationForwardTargets?: Record<string, string>
moderationForwardOrder?: string[]
moderationForwardSecretConfigured?: boolean
moderationForwardMaxRetry?: number
moderationForwardBackoffSeconds?: number[]
moderationForwardRecent?: ModerationForwardRecordVO[]
encryptionKeyConfigured: boolean
updatedAt?: string
@@ -1609,9 +1611,12 @@ export interface ModerationForwardRecordVO {
traceId: string
sourceEnv?: string
targetEnv?: string
status: 'CLAIMED' | 'NO_ENV' | 'PENDING' | 'SUCCESS' | 'RETRY' | 'FAILED' | 'TARGET_MISSING' | string
status: 'CLAIMED' | 'PENDING' | 'PROCESSING' | 'SUCCESS' | 'NO_ENV' | 'FAILED' | 'DEAD' | 'RETRY' | 'TARGET_MISSING' | string
retryCount?: number
lastError?: string
payload?: string
nextAttemptAt?: string
finishedAt?: string
createdAt?: string
updatedAt?: string
}
@@ -1662,6 +1667,8 @@ export interface SecureIntegrationConfigUpdate {
moderationForwardOrder?: string[]
moderationForwardSecret?: string
clearModerationForwardSecret?: boolean
moderationForwardMaxRetry?: number
moderationForwardBackoffSeconds?: number[]
}
/**
@@ -347,11 +347,26 @@
<a-input-number v-model:value="moderationForwardOrder[env.key]" :min="1" :max="3" :precision="0" />
</div>
</article>
<article class="field">
<div class="field__head"><span class="field__label">补偿最大重试次数</span></div>
<p class="field__desc">未认领或处理失败的任务按退避节奏补偿,超过次数置为 DEAD 并告警。</p>
<div class="field__control">
<a-input-number v-model:value="moderationForwardMaxRetry" :min="1" :max="10" :precision="0" />
</div>
</article>
<article class="field">
<div class="field__head"><span class="field__label">退避秒数(第 1-4 次)</span></div>
<p class="field__desc">默认 30 / 120 / 600 / 3600 秒,超出次数后沿用最后一个梯度。</p>
<div class="field__control forward-backoff">
<a-input-number v-for="(_, index) in moderationForwardBackoffSeconds" :key="index"
v-model:value="moderationForwardBackoffSeconds[index]" :min="1" :max="86400" :precision="0" />
</div>
</article>
</div>
<div class="forward-recent">
<div class="forward-recent__head">
<strong>最近转发结果</strong>
<span class="control-note">NO_ENV 表示所有目标环境均未认领,需人工排查;CLAIMED 表示已由目标环境处理。</span>
<strong>最近回调任务</strong>
<span class="control-note">接收即落库并立即应答微信;PENDING / PROCESSING 表示异步处理中,NO_ENV / FAILED 进入补偿,DEAD 需人工排查原始报文。</span>
</div>
<div v-if="!(secureStatus?.moderationForwardRecent || []).length" class="control-note">暂无转发记录</div>
<ul v-else class="forward-recent__list">
@@ -360,7 +375,12 @@
<span class="forward-recent__env">{{ item.sourceEnv || '-' }} → {{ item.targetEnv || '-' }}</span>
<span class="forward-recent__trace" :title="item.traceId">{{ item.traceId }}</span>
<span class="forward-recent__time">{{ formatProbeTime(item.createdAt) }}</span>
<span v-if="item.nextAttemptAt" class="forward-recent__time">下次补偿 {{ formatProbeTime(item.nextAttemptAt) }}</span>
<span v-if="item.lastError" class="forward-recent__error">{{ item.lastError }}</span>
<details v-if="item.payload" class="forward-recent__payload">
<summary>原始报文</summary>
<pre>{{ item.payload }}</pre>
</details>
</li>
</ul>
</div>
@@ -536,6 +556,8 @@ const moderationForwardEnabled = ref(false)
const moderationForwardTargets = reactive<Record<'dev' | 'sit' | 'prod', string>>({ dev: '', sit: '', prod: '' })
const moderationForwardOrder = reactive<Record<'dev' | 'sit' | 'prod', number>>({ dev: 1, sit: 2, prod: 3 })
const moderationForwardSecret = ref('')
const moderationForwardMaxRetry = ref(4)
const moderationForwardBackoffSeconds = reactive<number[]>([30, 120, 600, 3600])
const clearModerationForwardSecret = ref(false)
const savingModerationForward = ref(false)
const forwardEnvTargets = [
@@ -710,6 +732,11 @@ const load = async () => {
moderationForwardOrder[env.key] = position >= 0 ? position + 1 : index + 1
})
moderationForwardSecret.value = ''
moderationForwardMaxRetry.value = secureConfig.moderationForwardMaxRetry ?? 4
const loadedBackoff = secureConfig.moderationForwardBackoffSeconds || [30, 120, 600, 3600]
moderationForwardBackoffSeconds.forEach((_, index) => {
moderationForwardBackoffSeconds[index] = loadedBackoff[index] ?? loadedBackoff[loadedBackoff.length - 1] ?? 3600
})
clearModerationForwardSecret.value = false
mapSecrets.tencentWeb = ''
mapSecrets.amapWeb = ''
@@ -1037,8 +1064,15 @@ const saveModerationConfig = async () => {
}
const forwardStatusLabel = (status?: string) => ({
CLAIMED: '已认领', NO_ENV: '无环境认领',
PENDING: '待转发', SUCCESS: '已转发', RETRY: '待重试', FAILED: '失败', TARGET_MISSING: '目标未配置'
CLAIMED: '已认领',
PENDING: '待处理',
PROCESSING: '处理中',
SUCCESS: '已处理',
NO_ENV: '无环境认领',
FAILED: '失败待重试',
DEAD: '已终止',
RETRY: '待重试',
TARGET_MISSING: '目标未配置'
} as Record<string, string>)[status || ''] || '未知'
const saveModerationForwardConfig = async () => {
@@ -1067,7 +1101,9 @@ const saveModerationForwardConfig = async () => {
.sort((a, b) => moderationForwardOrder[a.key] - moderationForwardOrder[b.key])
.map(env => env.key),
moderationForwardSecret: moderationForwardSecret.value,
clearModerationForwardSecret: clearModerationForwardSecret.value
clearModerationForwardSecret: clearModerationForwardSecret.value,
moderationForwardMaxRetry: moderationForwardMaxRetry.value,
moderationForwardBackoffSeconds: [...moderationForwardBackoffSeconds]
})
moderationForwardSecret.value = ''
clearModerationForwardSecret.value = false
@@ -1349,6 +1385,14 @@ onMounted(() => {
}
.forward-recent__time { color: var(--text-color-secondary, #6b7280); }
.forward-recent__error { color: var(--danger-color, #c0392b); }
.forward-recent__payload { flex: 1 1 100%; }
.forward-recent__payload summary { cursor: pointer; color: var(--text-color-secondary, #6b7280); }
.forward-recent__payload pre {
margin: 4px 0 0;
font-size: 12px;
white-space: pre-wrap;
word-break: break-all;
}
@media (max-width: 760px) {
.settings-subsection__head { flex-direction: column; align-items: stretch; }
}