API-AI-002:AI Job 状态机与任务调度设计 #163

Open
opened 2026-06-10 21:01:46 +08:00 by wangdl · 0 comments
Owner

目标

设计 AI Runtime Job 的状态机、任务类型、锁定机制、重试机制、超时机制和幂等规则。

Job 类型

  • learning_state_analysis
  • weak_point_analysis
  • next_action_planning
  • quiz_generation
  • flashcard_generation

Job 状态

  • pending
  • locked
  • running
  • succeeded
  • failed
  • cancelled
  • expired

必需字段

  • id
  • userId
  • jobType
  • targetType
  • targetId
  • snapshotId
  • status
  • priority
  • idempotencyKey
  • lockedBy
  • lockedAt
  • lockUntil
  • startedAt
  • finishedAt
  • retryCount
  • maxRetryCount
  • timeoutSeconds
  • errorCode
  • errorMessage
  • createdAt
  • updatedAt

状态流转

pending → locked → running → succeeded
pending → locked → running → failed
failed → pending
running → expired
pending → cancelled
locked → expired

验收标准

  1. 输出 Job 状态机设计文档。
  2. 明确每个状态的进入条件和退出条件。
  3. 明确 Runtime 如何锁定任务。
  4. 明确 lockUntil 超时后如何释放任务。
  5. 明确 retryCount / maxRetryCount 规则。
  6. 明确 idempotencyKey 用于防止重复创建任务。
  7. 明确 Admin 后续可重跑 failed job。
  8. 明确 cancelled / expired 不应被 Runtime 再次消费。
## 目标 设计 AI Runtime Job 的状态机、任务类型、锁定机制、重试机制、超时机制和幂等规则。 ## Job 类型 - learning_state_analysis - weak_point_analysis - next_action_planning - quiz_generation - flashcard_generation ## Job 状态 - pending - locked - running - succeeded - failed - cancelled - expired ## 必需字段 - id - userId - jobType - targetType - targetId - snapshotId - status - priority - idempotencyKey - lockedBy - lockedAt - lockUntil - startedAt - finishedAt - retryCount - maxRetryCount - timeoutSeconds - errorCode - errorMessage - createdAt - updatedAt ## 状态流转 ``` pending → locked → running → succeeded pending → locked → running → failed failed → pending running → expired pending → cancelled locked → expired ``` ## 验收标准 1. 输出 Job 状态机设计文档。 2. 明确每个状态的进入条件和退出条件。 3. 明确 Runtime 如何锁定任务。 4. 明确 lockUntil 超时后如何释放任务。 5. 明确 retryCount / maxRetryCount 规则。 6. 明确 idempotencyKey 用于防止重复创建任务。 7. 明确 Admin 后续可重跑 failed job。 8. 明确 cancelled / expired 不应被 Runtime 再次消费。
wangdl added this to the M-API-AI-RUNTIME:API AI Runtime 调度与落库 milestone 2026-06-10 21:01:46 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#163
No description provided.