am-freescan/am-web/src/cmvr/common/utils/actionQueueTimeout.mjs

25 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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