2026-11-11 16:17:04 +08:00
|
|
|
|
export const DEFAULT_STEP_TIMEOUT_MS = 120000
|
|
|
|
|
|
export const MAX_QUEUE_TIMEOUT_MS = 1800000
|
|
|
|
|
|
export const SERVER_DEFAULT_QUEUE_TIMEOUT_MS = 300000
|
2026-11-02 17:38:34 +08:00
|
|
|
|
|
|
|
|
|
|
export function actionQueueTotalTimeout(steps = []) {
|
|
|
|
|
|
let total = 0, unlimited = false
|
2026-11-11 16:17:04 +08:00
|
|
|
|
if (steps.length > 100) throw new Error('动作队列最多100个步骤')
|
2026-11-02 17:38:34 +08:00
|
|
|
|
for (const step of steps) {
|
|
|
|
|
|
const timeout = Number(step.timeoutMs ?? DEFAULT_STEP_TIMEOUT_MS)
|
|
|
|
|
|
if (!Number.isInteger(timeout) || timeout < 0 || timeout > MAX_QUEUE_TIMEOUT_MS)
|
2026-11-11 16:17:04 +08:00
|
|
|
|
throw new Error('步骤超时须为0至1800000整数毫秒,0继承队列剩余时间')
|
2026-11-02 17:38:34 +08:00
|
|
|
|
unlimited ||= timeout === 0
|
|
|
|
|
|
total += timeout
|
|
|
|
|
|
}
|
|
|
|
|
|
if (unlimited) return 0
|
2026-11-11 16:17:04 +08:00
|
|
|
|
if (total > MAX_QUEUE_TIMEOUT_MS) throw new Error('队列总超时最多30分钟,请拆分队列或将步骤设为0使用边端默认5分钟')
|
2026-11-02 17:38:34 +08:00
|
|
|
|
return total
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-11 16:17:04 +08:00
|
|
|
|
// Allow the unary RPC its total runtime plus transport grace; zero means edge default, not infinity.
|
2026-11-02 17:38:34 +08:00
|
|
|
|
export function actionQueueRequestTimeout(steps) {
|
|
|
|
|
|
const total = actionQueueTotalTimeout(steps)
|
2026-11-11 16:17:04 +08:00
|
|
|
|
return (total === 0 ? SERVER_DEFAULT_QUEUE_TIMEOUT_MS : total) + 10000
|
2026-11-02 17:38:34 +08:00
|
|
|
|
}
|