修复(履约渠道): 收敛管道事件避免待办自动刷新
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { isFinancePipelineRealtimeJobId } from './scheduler-service.js'
|
||||
|
||||
test('只有财务履约管道任务允许广播 fulfillment_pipeline.changed', () => {
|
||||
for (const jobId of [
|
||||
'channel-assign',
|
||||
'carrier-dispatch',
|
||||
'product-normalize',
|
||||
'cost-snapshot',
|
||||
'sales-facts',
|
||||
'ledger-post',
|
||||
]) {
|
||||
assert.equal(isFinancePipelineRealtimeJobId(jobId), true)
|
||||
}
|
||||
|
||||
for (const jobId of [
|
||||
'voucher-consume-dispatch',
|
||||
'pdd_order_sync',
|
||||
'work-order-timeout',
|
||||
'deposit-unfreeze',
|
||||
'order-service-auto-publish',
|
||||
'data-retention',
|
||||
'',
|
||||
null,
|
||||
]) {
|
||||
assert.equal(isFinancePipelineRealtimeJobId(jobId), false)
|
||||
}
|
||||
})
|
||||
@@ -20,6 +20,18 @@ import { publishRealtimeEvent } from '../realtime/realtime-event-service.js'
|
||||
|
||||
const timers = new Map<string, NodeJS.Timeout>()
|
||||
const jobStates = new Map<string, JsonObject>()
|
||||
const FINANCE_PIPELINE_REALTIME_JOB_IDS = new Set([
|
||||
'channel-assign',
|
||||
'carrier-dispatch',
|
||||
'product-normalize',
|
||||
'cost-snapshot',
|
||||
'sales-facts',
|
||||
'ledger-post',
|
||||
])
|
||||
|
||||
export function isFinancePipelineRealtimeJobId(jobId: unknown) {
|
||||
return FINANCE_PIPELINE_REALTIME_JOB_IDS.has(String(jobId || '').trim())
|
||||
}
|
||||
|
||||
export function startScheduledJobs() {
|
||||
reloadScheduledJobs()
|
||||
@@ -204,13 +216,15 @@ async function runJob(job: JsonObject, { manual = false }: { manual?: boolean }
|
||||
}
|
||||
|
||||
function publishPipelineRealtimeChange(jobId: unknown, phase: string) {
|
||||
const normalizedJobId = String(jobId || '').trim()
|
||||
if (!isFinancePipelineRealtimeJobId(normalizedJobId)) return
|
||||
publishRealtimeEvent({
|
||||
type: 'fulfillment_pipeline.changed',
|
||||
entityId: 0,
|
||||
scopes: ['admin_fulfillment_pipelines'],
|
||||
operation: 'refresh',
|
||||
data: {
|
||||
jobId: String(jobId || '').trim(),
|
||||
jobId: normalizedJobId,
|
||||
phase: String(phase || '').trim(),
|
||||
},
|
||||
admin: true,
|
||||
|
||||
@@ -564,7 +564,6 @@ function applyAdminRealtimeEvent(
|
||||
event.scopes.includes('admin_fulfillment_pipelines')
|
||||
) {
|
||||
void queryClient.invalidateQueries({ queryKey: ['fulfillment-pipelines'] })
|
||||
void queryClient.invalidateQueries({ queryKey: ['fulfillment-pending'] })
|
||||
}
|
||||
|
||||
if (event.type === 'work_order.changed' && event.scopes.includes('admin_work_orders')) {
|
||||
|
||||
@@ -668,7 +668,7 @@ function PendingPanel() {
|
||||
<PercentTable
|
||||
rowKey={(row) => rowKey(row)}
|
||||
size="small"
|
||||
loading={query.isFetching}
|
||||
loading={query.isLoading}
|
||||
dataSource={query.data?.data?.items || []}
|
||||
columns={columns}
|
||||
pagination={buildAdminTablePagination({
|
||||
|
||||
@@ -26,6 +26,12 @@ test('履约管道状态由后台 SSE 失效刷新,不再 30 秒轮询', () =>
|
||||
assert.match(page, /SSE\s+自动刷新/)
|
||||
assert.ok(layout.includes("event.type === 'fulfillment_pipeline.changed'"))
|
||||
assert.ok(layout.includes("queryKey: ['fulfillment-pipelines']"))
|
||||
const pipelineRealtimeBlock = layout.slice(
|
||||
layout.indexOf("event.type === 'fulfillment_pipeline.changed'"),
|
||||
layout.indexOf("event.type === 'work_order.changed'"),
|
||||
)
|
||||
assert.ok(!pipelineRealtimeBlock.includes("queryKey: ['fulfillment-pending']"))
|
||||
assert.ok(page.includes('loading={query.isLoading}'))
|
||||
})
|
||||
|
||||
test('公共订单 SSE 允许匿名连接且只携带重读信号', () => {
|
||||
|
||||
Reference in New Issue
Block a user