fix(cluster): 等待 Worker 完全退出后执行跨节点验收

修正缩容期间 Deployment 已显示零就绪但旧 Worker Pod 尚在退出时仍可能领取验收任务的竞态。真实任务提交前现在会确认宁波 Worker Pod 数量为零,并在失败路径尝试取消未完成的测试任务。\n\n验证:node --check、bash -n、ShellCheck、git diff --check。
This commit is contained in:
2026-07-29 17:29:15 +08:00
parent a073c840ac
commit de1ce2274b
2 changed files with 14 additions and 3 deletions
+7 -1
View File
@@ -129,6 +129,8 @@ assert(typeof apiKey === 'string' && apiKey.startsWith('sk-gw-'), 'API key creat
assert(typeof apiKeyId === 'string' && apiKeyId.length > 0, 'API key ID is unavailable')
let result
let taskId
let taskSucceeded = false
try {
const assignableModels = await request('/api/v1/api-keys/assignable-models', { token: jwt })
const targetModels = (assignableModels.payload.items || []).filter(
@@ -185,7 +187,7 @@ try {
form,
})
assert(accepted.response.status === 202, `image edit returned ${accepted.response.status}, expected 202`)
const taskId = accepted.payload.taskId || accepted.payload.task_id || accepted.payload.task?.id
taskId = accepted.payload.taskId || accepted.payload.task_id || accepted.payload.task?.id
assert(/^[0-9a-f-]{36}$/.test(taskId || ''), 'image edit response has no task ID')
let task
@@ -202,8 +204,12 @@ try {
assert(task?.status === 'succeeded', `task ${taskId} did not succeed before timeout`)
const resultURLs = [...new Set(collectHTTPSURLs(task.result))]
assert(resultURLs.length > 0, 'task result contains no shared HTTPS URL')
taskSucceeded = true
result = { taskId, sourceSHA256, resultURL: resultURLs[0], model }
} finally {
if (taskId && !taskSucceeded) {
await request(`/api/v1/tasks/${taskId}/cancel`, { method: 'POST', token: apiKey }).catch(() => {})
}
if (apiKeyId) {
await request(`/api/v1/api-keys/${apiKeyId}`, { method: 'DELETE', token: jwt }).catch(() => {})
}