use idempotency key for finance export replay
This commit is contained in:
@@ -112,7 +112,9 @@ async function poll(context, taskId, expected = 'SUCCEEDED', attempts = 45) {
|
|||||||
|
|
||||||
async function createTask(context, type, parameters, suffix, expectedHeaders, expectedTokens = []) {
|
async function createTask(context, type, parameters, suffix, expectedHeaders, expectedTokens = []) {
|
||||||
const body = { exportType: type, format: 'XLSX', taskName: `${context.marker}-${suffix}`, parameters }
|
const body = { exportType: type, format: 'XLSX', taskName: `${context.marker}-${suffix}`, parameters }
|
||||||
const createdResponse = await context.request('POST', '/api/platform/v1/files/export-tasks', body)
|
const idempotencyKey = `${context.marker}-export-${type}-${suffix}`.slice(0, 128)
|
||||||
|
const createdResponse = await context.request('POST', '/api/platform/v1/files/export-tasks', body,
|
||||||
|
context.token, { 'Idempotency-Key': idempotencyKey })
|
||||||
const created = context.apiSuccess(MODULE, `${type} 创建导出任务`, createdResponse,
|
const created = context.apiSuccess(MODULE, `${type} 创建导出任务`, createdResponse,
|
||||||
`type=${type}`, OPTIONS)
|
`type=${type}`, OPTIONS)
|
||||||
const taskId = id(created?.id)
|
const taskId = id(created?.id)
|
||||||
@@ -122,7 +124,8 @@ async function createTask(context, type, parameters, suffix, expectedHeaders, ex
|
|||||||
`taskId=${taskId || 'missing'}, status=${created?.status ?? 'missing'}`, OPTIONS)
|
`taskId=${taskId || 'missing'}, status=${created?.status ?? 'missing'}`, OPTIONS)
|
||||||
if (!taskId) return null
|
if (!taskId) return null
|
||||||
|
|
||||||
const duplicateResponse = await context.request('POST', '/api/platform/v1/files/export-tasks', body)
|
const duplicateResponse = await context.request('POST', '/api/platform/v1/files/export-tasks', body,
|
||||||
|
context.token, { 'Idempotency-Key': idempotencyKey })
|
||||||
const duplicate = context.apiSuccess(MODULE, `${type} 重复请求`, duplicateResponse, '', OPTIONS)
|
const duplicate = context.apiSuccess(MODULE, `${type} 重复请求`, duplicateResponse, '', OPTIONS)
|
||||||
context.assert(MODULE, `${type} 60 秒同参请求合并`, duplicateResponse, id(duplicate?.id) === taskId,
|
context.assert(MODULE, `${type} 60 秒同参请求合并`, duplicateResponse, id(duplicate?.id) === taskId,
|
||||||
`original=${taskId}, duplicate=${id(duplicate?.id) || 'missing'}`, OPTIONS)
|
`original=${taskId}, duplicate=${id(duplicate?.id) || 'missing'}`, OPTIONS)
|
||||||
|
|||||||
Reference in New Issue
Block a user