VEGA 引擎 · 构建任务 API (0.1.0)

Download OpenAPI specification:

Vega Backend 构建任务(BuildTask)相关 API。

BuildTask 是顶级独立资源,每条 task 关联 1 个 Resource,对其执行 streaming / batch 两种模式之一的构建。状态机:

pending → running → stopping → stopped ↘ completed ↘ failed ↘ cancelled

外部仅可触发 start / stop 两个动作;其它状态由 worker 内部转移,外部只读。 start / stop 返回 HTTP 202 且 body 为空,仅表示"指令被接受",不表示 status 已切换;持久化 status 由 worker 实际执行时写入,客户端如需感知应轮询 GET。

端点设计遵循 [vega-backend/CLAUDE.md] 的"端点设计规则":批量删除走 path (DELETE /build-tasks/{ids},逗号分隔),不提供 /resources/{id}/build-tasks 嵌套列表视图——按父资源过滤一律走 GET /build-tasks?resource_id={id}。

schedule_id 和 trigger_type 是服务端写入的只读来源字段。手动任务的 schedule_id 为空,trigger_type=manual;由 BuildSchedule 创建的任务为 scheduled。 删除调度不删除已生成任务,也不清除其 schedule_id。手动创建接口不能伪造这些字段。 任务详情另返回可选只读 schedule_name,为关联计划的当前名称,不是触发时快照; 手动任务、计划已删除或读取计划失败时省略该字段,仍保留任务及既有 schedule_id。 任务列表不返回 schedule_name。

每个新任务均有服务端分配的只读 index_name。Full BuildTask 使用新的 vega-build-<uuidv7> 物理索引;Incremental BuildTask 快照创建时 Resource 的当前 index_name,不会新建索引。索引名不承载 Resource 或 Task ID,调用方不得根据其解析业务 ID。

获取构建任务列表

分页获取构建任务;支持按 resource_id / catalog_id / schedule_id / trigger_type / status / mode / execute_type 过滤。

Authorizations:
OAuth2
query Parameters
schedule_id
string

按触发任务的 BuildSchedule ID 过滤;计划删除后仍可查询已有任务

trigger_type
string
Enum: "manual" "scheduled"

按手动或调度来源过滤

resource_id
string

按归属 resource 过滤

catalog_id
string

按归属 catalog 过滤

status
Array of strings
Items Enum: "pending" "running" "stopping" "stopped" "completed" "failed" "cancelled"

按状态过滤;多个状态重复传递该参数,状态之间为 OR 关系。

mode
string
Enum: "streaming" "batch"

按任务模式过滤

execute_type
string
Enum: "full" "incremental" "keys"

按批处理执行方式过滤;流式任务不匹配该筛选条件

offset
integer <int64> >= 0
Default: 0

分页偏移量,>=0,默认 0

limit
integer <int64> [ -1 .. 1000 ]
Default: 20

每页数量,1-1000,-1 表示不分页,默认 20

sort
string
Default: "create_time"
Enum: "create_time" "start_time" "finish_time" "last_progress_time"

排序字段,默认按创建时间排序

direction
string
Default: "desc"
Enum: "asc" "desc"

排序方向,默认 desc

Responses

Response samples

Content type
application/json
{
  • "entries": [
    ],
  • "total_count": 0
}

创建构建任务

为指定 Resource 创建构建任务。同资源的批处理串行执行。创建 full 或 incremental 时, 已有 active Task(pending / running / stopping)返回 400 VegaBackend.BuildTask.Exist。 keys 任务可在资源忙碌时排队,轮到执行时解析当前发布索引。

  • 当前版本暂不支持 streaming 模式。
  • batch 模式要求 primary_key_fields 非空。incremental 还要求 incremental_fields 非空。 full 可省略 incremental_fields。未配置时,任务依旧记录主键游标供断点续跑, 构建期间的源端变更可能遗漏,可通过再次全量刷新补齐。
  • incremental 要求 local_status=available 的已发布本地索引。readonly 的旧索引仍可查询,须全量重建后才能继续增量。 缺少可写索引、基线为空或基线无效时返回 409 VegaBackend.BuildTask.IncrementalBaselineUnavailable, 应按当前配置执行全量。空表全量提交的有效空游标可以用于增量;后台不从索引恢复基线。 游标之前的变更和源端删除可能不会反映到索引中。
  • keys 要求一个已发布且可写的本地索引以及非空 keys。每项是完整主键对象, 最多接收 100 项,重复主键只计算一次。整数值须保持精确 JSON 整数,字符串值为 1 至 4096 字节。 传给其他执行类型的非空或空数组均无效。无效输入返回 400 VegaBackend.BuildTask.InvalidKeys。 不可写的索引返回 409 VegaBackend.BuildTask.KeysIndexUnavailable。 调用方应在源端变更已提交后创建任务。Catalog 须连接到能读到已提交变更的源库。 Worker 执行时检查源连接器是否支持表读取会话。缺少此能力时,任务标记为 failed,索引内容保留。 任务通过连接器的表读取会话,一次查询读取去重后的整组主键,无需统计总数。 对账以 Catalog 连接账号可见的数据为准。查询失败或结果不完整时任务失败,索引内容保留。 任务完成代表结果已可搜索。按 key 同步不读取或推进扫描游标。
  • PostgreSQL、MySQL/MariaDB 的 InnoDB 表在每次 full 执行中使用同一源端事务统计总数并打开结果集,逐批消费该结果集。 中断后从任务游标打开新的读取会话,跨运行的批次可能看到不同的数据。没有表读取会话的来源继续逐批执行查询。
  • 构建任务要求 Resource 已配置主键。Resource 层在保存配置和构建准入时校验主键及增量字段。 字段必须存在于当前 schema 中、不能重复且必须使用受支持的类型,否则构建接口返回 400。
  • index_name 由服务端分配并在详情、列表响应中返回;请求体不接受该字段。
  • 创建后 status = pending。

需要所属 Catalog 的 task_manage,并通过目标 Resource 的查看权限检查。 新授权写入时 task_manage 的完整依赖为 resource_manage、view_detail; 既有授权不自动补齐,运行时不额外检查 requires。Resource 的显式查看拒绝仍生效。 读取 Resource/Catalog 的已分类错误保留原状态和错误码(如 403 Public.Forbidden、404); 未分类读取故障返回 500。失败时不创建任务或触发调度。

Authorizations:
OAuth2
Request Body schema: application/json
required
resource_id
required
string

关联 Resource ID(必填)

mode
required
string
Enum: "streaming" "batch"

任务模式

execute_type
string
Enum: "incremental" "full" "keys"

batch 执行类型;省略时服务端默认 full

Array of objects (BuildTaskKeys) [ 1 .. 100 ] items [ items non-empty ]

仅对 keys 任务必填。每个对象必须包含 Resource 的所有主键字段。

Responses

Request samples

Content type
application/json
{
  • "resource_id": "string",
  • "mode": "streaming",
  • "execute_type": "incremental",
  • "keys": [
    ]
}

Response samples

Content type
application/json
{
  • "id": "string"
}

获取构建任务详情

按主键任务返回持久化的 keys,供调用方核对同步范围。

Authorizations:
OAuth2
path Parameters
id
required
string

BuildTask ID;DELETE 时可传逗号分隔的 ID 列表

Responses

Response samples

Content type
application/json
{
  • "id": "string",
  • "resource_id": "string",
  • "catalog_id": "string",
  • "schedule_id": "string",
  • "trigger_type": "manual",
  • "catalog_name": "string",
  • "resource_name": "string",
  • "schedule_name": "string",
  • "status": "pending",
  • "mode": "streaming",
  • "execute_type": "incremental",
  • "keys": [
    ],
  • "index_name": "string",
  • "total_count": 0,
  • "synced_count": 0,
  • "synced_mark": "string",
  • "error_msg": "string",
  • "creator": {
    },
  • "create_time": 0,
  • "start_time": 0,
  • "finish_time": 0,
  • "last_progress_time": 0,
  • "failure_detail": "string",
  • "index_config": {
    }
}

删除构建任务(整体事务)

整体事务语义:所有 id 通过预校验后才进入删除阶段,任一预校验失败整批不删。

预校验顺序:

  1. 任一 id 处于 pending / running / stopping → 409 VegaBackend.BuildTask.HasRunningExecution, error_details 携带 { active_ids: [...] }。状态拦截不可绕过;pending/running 必须先 stop,stopping 必须等待停止完成后再删。
  2. 任一 id 不存在(且未启用 ignore_missing)→ 404 VegaBackend.BuildTask.NotFound, error_details 携带 { missing_ids: [...] }。
  3. 全部通过 → 只删除结束态 Task 数据库记录,返回 204。删除 Task 不修改 Resource 本地索引状态,也不删除 OpenSearch 索引。
Authorizations:
OAuth2
path Parameters
id
required
string

BuildTask ID;DELETE 时可传逗号分隔的 ID 列表

query Parameters
ignore_missing
boolean
Default: false

放宽不存在性检查:缺失 id 视为已删除(静默跳过),其它 id 正常删。 不影响 pending/running/stopping 拦截。

Responses

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}

启动构建任务

合法状态转移:status ∈ {stopped, failed} → pending → running。 failed 允许重试;pending 已在队列中、completed 已结束,二者均不允许 start。 batch 任务默认按 synced_mark 续跑;incremental 任务不支持 reset=true,传入时返回 409 VegaBackend.BuildTask.IncrementalResetUnsupported。full 任务仅在 reset=true 时清除进度并从头重建, 不修改原始 execute_type; worker 实际开始执行时会清空 error_msg。

按原执行类型重新校验 Resource 构建字段。full 需要主键。incremental 还需要增量字段 和任务所对应的 local_status=available 的已发布本地索引。缺少可写索引、基线为空或基线无效时, 返回 409 VegaBackend.BuildTask.IncrementalBaselineUnavailable。按当前配置完成全量后可创建新的增量任务。 keys 以原始主键集合重新回源,允许排队并在执行时选择当前索引。它只接受默认的 reset=false。

响应 status 滞后:HTTP 202 表示"启动指令已被接受并入队",不表示 status 已切换为 running。worker 实际执行时才会写为 running, 客户端如需确认应轮询 GET。响应 body 为空。

非幂等:对非 stopped / failed 状态的 task 调用 start 返回 409 VegaBackend.BuildTask.InvalidStateTransition。

启动前重新读取 Resource;明确的权限拒绝保留 403 Public.Forbidden, 不存在保留 404,未分类读取故障返回 500。失败时不更新任务状态或触发调度。

Authorizations:
OAuth2
path Parameters
id
required
string

BuildTask ID

Request Body schema: application/json
optional
reset
boolean
Default: false

仅对原始 execute_type=full 的任务有效;为 true 时清空进度并从头执行。incremental 或 keys 任务传 true 返回 409 冲突

Responses

Request samples

Content type
application/json
{
  • "reset": false
}

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}

停止构建任务

合法状态转移:

  • pending → stopped:任务尚在队列中,直接标记停止,worker 出队后会跳过。
  • running → stopping:正常停止,worker 在批间检查点退出后写 stopped。

响应 status 滞后:HTTP 202 表示"停止指令已被记录"。running 任务的 stopping → stopped 由 worker 异步推进,客户端可轮询 GET 拿最新 status。响应 body 为空。

非幂等:对非 pending / running 状态的 task 调 stop 返回 409; stopping 中再次 stop 也返回 409 VegaBackend.BuildTask.InvalidStateTransition。

Authorizations:
OAuth2
path Parameters
id
required
string

BuildTask ID

Responses

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}