chore(logging): 降噪 PDD 同步与发单消费者常态日志
将无新单/全跳过的处理完成日志降到 debug,并压缩 decisions 详情,避免 app 日志被按日切碎。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import type { JsonObject } from '../../types/json.js'
|
||||
import type { OrderItemRow, OrderRow } from '../../types/repository/rows.js'
|
||||
import { generateWorkOrderNo, randomId } from '../../utils/random.js'
|
||||
import { nowIso } from '../../utils/time.js'
|
||||
import { logInfo, logWarn } from '../../utils/logger.js'
|
||||
import { logDebug, logInfo, logWarn } from '../../utils/logger.js'
|
||||
import { safeParseJson } from '../admin/admin-query-utils.js'
|
||||
import { createWorkOrderMaterialAdminNotification } from '../admin/admin-notification-service.js'
|
||||
import {
|
||||
@@ -272,23 +272,29 @@ export async function syncWorkerOrdersForSourceOrder(
|
||||
}
|
||||
}
|
||||
|
||||
logInfo('[worker-order-consumer]', '发单平台消费者处理完成', {
|
||||
const summary = {
|
||||
source: options.source || 'source_order',
|
||||
orderId: order.id,
|
||||
platformOrderId: order.platform_order_id,
|
||||
orderItemCount: orderItems.length,
|
||||
createdCount: created.length,
|
||||
skippedCount: skipped.length,
|
||||
decisions,
|
||||
})
|
||||
skipReasons: formatDecisionReasonCounts(skipped),
|
||||
}
|
||||
|
||||
// 常态「全跳过」每轮 PDD upsert 都会触发,降到 debug,避免日志按天被切碎。
|
||||
if (created.length > 0) {
|
||||
logInfo('[worker-order-consumer]', '发单平台消费者处理完成', summary)
|
||||
} else {
|
||||
logDebug('[worker-order-consumer]', '发单平台消费者无新建工单', summary)
|
||||
}
|
||||
|
||||
const failedDecisions = decisions.filter((decision) => decision.result === 'failed')
|
||||
if (failedDecisions.length > 0) {
|
||||
logWarn('[worker-order-consumer]', '发单平台消费者存在未成功落库的订单项', {
|
||||
source: options.source || 'source_order',
|
||||
orderId: order.id,
|
||||
platformOrderId: order.platform_order_id,
|
||||
decisions: failedDecisions,
|
||||
...summary,
|
||||
failedCount: failedDecisions.length,
|
||||
failedReasons: formatDecisionReasonCounts(failedDecisions),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -323,3 +329,17 @@ function buildWorkerConsumerDecision(
|
||||
...detail,
|
||||
}
|
||||
}
|
||||
|
||||
function formatDecisionReasonCounts(decisions: Array<Record<string, unknown>>) {
|
||||
const counts = summarizeDecisionReasons(decisions)
|
||||
return Object.keys(counts).length > 0 ? JSON.stringify(counts) : ''
|
||||
}
|
||||
|
||||
function summarizeDecisionReasons(decisions: Array<Record<string, unknown>>) {
|
||||
const counts: Record<string, number> = {}
|
||||
for (const decision of decisions) {
|
||||
const reason = String(decision.reason || decision.result || 'unknown').trim() || 'unknown'
|
||||
counts[reason] = (counts[reason] || 0) + 1
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user