fix(clearance): 修正同步状态轮询与请求类型
This commit is contained in:
parent
9f3fb23265
commit
2aef8010db
@ -661,6 +661,7 @@ export function ClearanceView({
|
||||
const taskScrollRef = useRef<HTMLDivElement>(null)
|
||||
const [taskRefreshKey, setTaskRefreshKey] = useState(0)
|
||||
const taskProgressRetryCountRef = useRef(0)
|
||||
const handledProgressSyncRef = useRef<string | null>(null)
|
||||
|
||||
const [scores, setScores] = useState<ScoresData | null>(null)
|
||||
const [scorePeriod, setScorePeriod] = useState('')
|
||||
@ -813,18 +814,43 @@ export function ClearanceView({
|
||||
if (!progressStale) {
|
||||
taskProgressRetryCountRef.current = 0
|
||||
}
|
||||
void requestJson<{ queued: boolean }>(
|
||||
void requestJson<{
|
||||
queued: boolean
|
||||
status?: {
|
||||
running: boolean
|
||||
lastError: string
|
||||
through: string | null
|
||||
lastFinishedAt: string | null
|
||||
}
|
||||
}>(
|
||||
'/api/supply-chain/clearance/tasks/progress-refresh',
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ periodKey: data.periodKey }),
|
||||
},
|
||||
)
|
||||
.then(() => {
|
||||
if (controller.signal.aborted || !progressStale) return
|
||||
.then((response) => {
|
||||
const syncFinishedAt = response.status?.lastFinishedAt ?? null
|
||||
const hasUnhandledFinishedSync = Boolean(
|
||||
syncFinishedAt && handledProgressSyncRef.current !== syncFinishedAt,
|
||||
)
|
||||
const shouldPoll = Boolean(
|
||||
response.queued
|
||||
|| response.status?.running
|
||||
|| response.status?.lastError
|
||||
|| progressStale
|
||||
|| hasUnhandledFinishedSync,
|
||||
)
|
||||
if (syncFinishedAt && !response.status?.running) {
|
||||
handledProgressSyncRef.current = syncFinishedAt
|
||||
}
|
||||
if (controller.signal.aborted || !shouldPoll) return
|
||||
const attempt = taskProgressRetryCountRef.current
|
||||
const delay = TASK_PROGRESS_RETRY_DELAYS[attempt]
|
||||
if (delay == null) return
|
||||
if (delay == null) {
|
||||
setTaskError('发货同步仍在处理中,请稍后手动刷新')
|
||||
return
|
||||
}
|
||||
taskProgressRetryCountRef.current += 1
|
||||
progressRetryTimer = window.setTimeout(async () => {
|
||||
try {
|
||||
@ -835,7 +861,6 @@ export function ClearanceView({
|
||||
}>(
|
||||
`/api/supply-chain/clearance/tasks/progress-refresh?period=${encodeURIComponent(data.periodKey)}`,
|
||||
{ signal: controller.signal },
|
||||
2,
|
||||
)
|
||||
if (controller.signal.aborted) return
|
||||
if (!status.running && status.lastError) {
|
||||
@ -854,6 +879,9 @@ export function ClearanceView({
|
||||
})
|
||||
.catch((reason: Error) => {
|
||||
console.warn('[clearance] progress refresh queue failed', reason)
|
||||
if (!controller.signal.aborted) {
|
||||
setTaskError('无法启动发货同步,请稍后手动刷新')
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((reason: Error) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user