修复(履约渠道): 收敛管道事件避免待办自动刷新

This commit is contained in:
yml
2026-11-18 19:54:01 +08:00
parent 86c8417d4b
commit 97a98ac162
5 changed files with 52 additions and 3 deletions
@@ -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,