优化
This commit is contained in:
@@ -24,6 +24,19 @@ function validPdf(response) {
|
||||
&& response.bytes?.length > 4 && new TextDecoder().decode(response.bytes.slice(0, 4)) === '%PDF'
|
||||
}
|
||||
|
||||
async function waitForCompletedMeasurement(context, measurementPath, attempts = 30) {
|
||||
let response = null
|
||||
let measurement = null
|
||||
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
||||
response = await context.request('GET', measurementPath)
|
||||
measurement = response?.http === 200 && String(response?.body?.code) === '200'
|
||||
? response.body.data : null
|
||||
if (measurement?.processStatus === 'WAIT_SPLIT') return { response, measurement, attempts: attempt }
|
||||
if (attempt < attempts) await new Promise((resolve) => setTimeout(resolve, 1_000))
|
||||
}
|
||||
return { response, measurement, attempts }
|
||||
}
|
||||
|
||||
async function provisionWarehouseResources(context, { inboundId, warehouseId, totalVolumeCbm }) {
|
||||
const palletCount = Math.ceil(Number(totalVolumeCbm) / DEFAULT_PALLET_CAPACITY_CBM)
|
||||
if (!warehouseId || !Number.isFinite(palletCount) || palletCount < 1) return false
|
||||
@@ -394,8 +407,13 @@ export async function run(context) {
|
||||
context.apiSuccess(MODULE, 'Admin 审核通过墨家测量', approvalResponse,
|
||||
`measurementId=${asId(draft.measurementId)}`, OPTIONS)
|
||||
|
||||
const finalResponse = await context.request('GET', measurementPath)
|
||||
const finalMeasurement = context.apiSuccess(MODULE, '查询审核后的最终测量状态', finalResponse, '', OPTIONS)
|
||||
// Measurement approval may enqueue pricing/inbound completion. Poll the
|
||||
// public projection instead of treating the transient WAIT_PRICING state as
|
||||
// a smart-loading candidate or manufacturing fixture state in the script.
|
||||
const completed = await waitForCompletedMeasurement(context, measurementPath)
|
||||
const finalResponse = completed.response
|
||||
const finalMeasurement = context.apiSuccess(MODULE, '查询审核后的最终测量状态', finalResponse,
|
||||
`pollAttempts=${completed.attempts}`, OPTIONS)
|
||||
context.assert(MODULE, '审核后入库与测量状态闭环且结果未变化', finalResponse,
|
||||
finalMeasurement?.processStatus === 'WAIT_SPLIT' && finalMeasurement?.measureReviewStatus === 'APPROVED'
|
||||
&& finalMeasurement?.measurementStatus === 'APPROVED'
|
||||
@@ -407,6 +425,7 @@ export async function run(context) {
|
||||
context.createdResources.inboundMeasurement = {
|
||||
marker: context.marker, tenantId, inboundId, measurementId: asId(draft.measurementId),
|
||||
boxCode, finalStatus: finalMeasurement?.measurementStatus || null,
|
||||
processStatus: finalMeasurement?.processStatus || null,
|
||||
}
|
||||
finishScenario(context, start)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user