再跳回第 1 步
This commit is contained in:
@@ -399,18 +399,55 @@ export async function refreshKuaishouCloudTaskBindUrl(task, options = {}) {
|
||||
}
|
||||
|
||||
const cloudContext = resolvePersistedCloudtentaclesContext()
|
||||
const bindUrlResult = await getCloudtentaclesBindUrl({
|
||||
...cloudContext,
|
||||
key: flow.binding.vnKey,
|
||||
id: flow.binding.vnId,
|
||||
})
|
||||
const bindUrl = String(bindUrlResult.bindUrl || '').trim()
|
||||
const oldVnKey = flow.binding.vnKey
|
||||
const oldVnId = flow.binding.vnId
|
||||
const oldVnPhone = flow.binding.vnPhone
|
||||
|
||||
if (!bindUrl) {
|
||||
throw createHttpError('cloudtentacles 未返回新的绑定链接', {
|
||||
statusCode: 502,
|
||||
errorCode: 'kuaishou_cloud_empty_bind_url',
|
||||
await backCloudtentaclesVirtualNumber({
|
||||
...cloudContext,
|
||||
key: oldVnKey,
|
||||
id: oldVnId,
|
||||
})
|
||||
|
||||
await createTaskEvent(task.id, 'kuaishou_cloud_expired_bind_number_returned', {
|
||||
source: String(options.source || 'system').trim() || 'system',
|
||||
vnKey: oldVnKey,
|
||||
vnId: oldVnId,
|
||||
vnPhoneMasked: maskPhone(oldVnPhone),
|
||||
actor,
|
||||
}, now)
|
||||
|
||||
let preparedBinding
|
||||
try {
|
||||
preparedBinding = await prepareKuaishouCloudBindResourceWithFallback({
|
||||
cloudContext,
|
||||
vnKeyCandidates: resolveKuaishouCloudVnKeyCandidates({
|
||||
flow,
|
||||
binding: flow.binding,
|
||||
}),
|
||||
})
|
||||
|
||||
if (!String(preparedBinding.bindUrl || '').trim()) {
|
||||
throw createHttpError('cloudtentacles 未返回新的绑定链接', {
|
||||
statusCode: 502,
|
||||
errorCode: 'kuaishou_cloud_empty_bind_url',
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
const failedTask = await markKuaishouCloudBindUrlRefreshFailed(task, {
|
||||
taskContext,
|
||||
flow,
|
||||
now,
|
||||
actor,
|
||||
error,
|
||||
})
|
||||
|
||||
return {
|
||||
task: failedTask,
|
||||
claimUrl: buildClaimUrl(String(task.primary_claim_token || task.claim_token || '')),
|
||||
token: String(task.primary_claim_token || task.claim_token || ''),
|
||||
flow: normalizeKuaishouCloudFlow(parseTaskContext(failedTask).kuaishouCloudFulfillment),
|
||||
}
|
||||
}
|
||||
|
||||
const nextContext = {
|
||||
@@ -420,7 +457,10 @@ export async function refreshKuaishouCloudTaskBindUrl(task, options = {}) {
|
||||
binding: {
|
||||
...flow.binding,
|
||||
prepareStatus: 'ready',
|
||||
bindUrl,
|
||||
vnKey: preparedBinding.vnKey,
|
||||
vnId: preparedBinding.vnId,
|
||||
vnPhone: preparedBinding.vnPhone,
|
||||
bindUrl: preparedBinding.bindUrl,
|
||||
bindPreparedAt: now,
|
||||
bindExpiresAt: resolveKuaishouCloudBindUrlExpiresAt(now),
|
||||
bindProbeAt: null,
|
||||
@@ -456,8 +496,11 @@ export async function refreshKuaishouCloudTaskBindUrl(task, options = {}) {
|
||||
|
||||
await createTaskEvent(task.id, 'kuaishou_cloud_bind_url_refreshed', {
|
||||
source: String(options.source || 'system').trim() || 'system',
|
||||
vnId: flow.binding.vnId,
|
||||
vnPhoneMasked: maskPhone(flow.binding.vnPhone),
|
||||
oldVnId,
|
||||
oldVnPhoneMasked: maskPhone(oldVnPhone),
|
||||
vnKey: preparedBinding.vnKey,
|
||||
vnId: preparedBinding.vnId,
|
||||
vnPhoneMasked: maskPhone(preparedBinding.vnPhone),
|
||||
actor,
|
||||
}, now)
|
||||
|
||||
@@ -489,7 +532,8 @@ export async function probeKuaishouCloudTaskBindUrl(task, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.force && flow.binding.bindProbeAt && Date.now() - Date.parse(flow.binding.bindProbeAt) < 15000) {
|
||||
const probeIntervalMs = Number(resolveCloudtentaclesConfig().bindUrlProbeIntervalSeconds || 30) * 1000
|
||||
if (!options.force && flow.binding.bindProbeAt && Date.now() - Date.parse(flow.binding.bindProbeAt) < probeIntervalMs) {
|
||||
return {
|
||||
task,
|
||||
flow,
|
||||
@@ -552,6 +596,65 @@ export async function probeKuaishouCloudTaskBindUrl(task, options = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} task
|
||||
* @param {{ taskContext?: any, flow?: any, now?: string, actor?: any, error?: unknown }} [input]
|
||||
*/
|
||||
async function markKuaishouCloudBindUrlRefreshFailed(task, {
|
||||
taskContext,
|
||||
flow,
|
||||
now,
|
||||
actor,
|
||||
error,
|
||||
} = {}) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error || '新绑定链接准备失败')
|
||||
const nextContext = {
|
||||
...taskContext,
|
||||
kuaishouCloudFulfillment: {
|
||||
...flow,
|
||||
binding: {
|
||||
...flow.binding,
|
||||
prepareStatus: 'pending',
|
||||
vnId: 0,
|
||||
vnPhone: '',
|
||||
bindUrl: '',
|
||||
bindPreparedAt: null,
|
||||
bindExpiresAt: null,
|
||||
bindProbeAt: now,
|
||||
bindProbeStatus: 'refresh_failed',
|
||||
bindProbeMessage: errorMessage,
|
||||
roleName: '',
|
||||
roleId: '',
|
||||
},
|
||||
role: {
|
||||
status: 'pending',
|
||||
name: '',
|
||||
rid: '',
|
||||
refreshedAt: now,
|
||||
errorMessage: '绑定链接已过期,旧号码已退还,新链接准备失败,请稍后刷新或联系客服处理',
|
||||
rawInfo: null,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const updatedTask = await updateTask(task.id, {
|
||||
task_status: 'pending_binding_prepare',
|
||||
role_id: '',
|
||||
role_name: '',
|
||||
last_error: `绑定链接过期,旧号码已退还,新链接准备失败:${errorMessage}`,
|
||||
context_json: JSON.stringify(nextContext),
|
||||
updated_at: now,
|
||||
})
|
||||
|
||||
await createTaskEvent(task.id, 'kuaishou_cloud_bind_url_refresh_failed', {
|
||||
source: 'system_refresh_expired_bind_url',
|
||||
errorMessage,
|
||||
actor,
|
||||
}, now)
|
||||
|
||||
return updatedTask
|
||||
}
|
||||
|
||||
export async function refreshKuaishouCloudTaskRoleInfo(task, options = {}) {
|
||||
if (!isKuaishouCloudTask(task)) {
|
||||
throw createHttpError('当前任务不是快手 Cloud 履约任务', {
|
||||
|
||||
Reference in New Issue
Block a user