> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chaintable.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 用 Pipeline 跑起来

> 建好表、写好 Function 之后，用 Pipeline 的两个动词把管道跑起来：backfill() 补历史，update() 追新块。

搭好了表和转换函数之后，剩下的就是 `Pipeline` 的两个动词：

```python theme={null}
from blockx import Pipeline, Trigger, SOURCE_ROW

pipe = Pipeline(
    triggers=[Trigger(table="chain.trace.eth", func=to_transfer, params=[SOURCE_ROW, "eth"])],
    target_table="myspace.transfers.eth",
    # depends=[...],   # 可选：转换逻辑里要点查、需要保证已追平的表
)

pipe.backfill(block_start=25_000_001, block_end=25_100_000)   # 历史批量回填
pipe.update()                                                  # 长驻，追新块
```

<Tip>
  转换函数实时和回填**完全复用同一份**，不需要为回填单独写一套逻辑。
</Tip>

## `backfill()`：批量补历史

```python theme={null}
result = pipe.backfill(block_start=25_000_001, block_end=25_100_000)
```

* `block_start`：起点，不能低于目标表的 [start height](/indexing/tables/start-height)
* `block_end`：不填 = 追到源表当前的共识高度。填得比这个值高会直接报错，一个任务都不会提交

内部会按区块高度自动换算成 bundle 批量处理，这些都不需要你操心。跑完会打印一份汇总：

```
已提交 998 段，失败 2 段
写入行数：约 42,381 行
失败区间：
  [25_050_001, 25_051_000]  code=WORKER_TIMEOUT
重跑命令：pipe.backfill(block_start=25_050_001, block_end=25_051_000)
```

失败的段不会中途重试，会在整段跑完后歇 30 秒统一重跑一遍，最多两轮。想自己接住结果处理：

```python theme={null}
result = pipe.backfill(block_start=25_000_001, block_end=25_100_000)
if not result.ok:
    for lo, hi, code, msg in result.failed_ranges:
        pipe.backfill(block_start=lo, block_end=hi)   # 写入幂等，重跑安全
```

<Warning>
  **"已提交"不等于"已落库"。** 汇总里的成功数只代表任务被 worker 受理，真正写库是后台异步完成的。要确认数据真的落库了，看目标表的 `_write` 子表，或者用 [Completeness by Height](/indexing/tables/completeness) 直接看哪些高度段已经完成。
</Warning>

<Warning>
  **回填不会触发下游订阅事件。** 如果有其他管道在订阅你回填的这张表，它们不会自动收到这些高度的通知——下游也需要主动发起一次回填才能补上这段。
</Warning>

## `update()`：长驻，追新块

```python theme={null}
pipe.update()   # 长驻不退出
```

启动时先把目标表补到当前的上游高度，追平后转入订阅，跟着新块持续处理。

<Warning>
  订阅意外中断又重连之间落下的高度，`update()` 不会自动回头补——需要你自己发现，手动调一次 `pipe.backfill()` 补齐这段。
</Warning>

## 需要点查另一张表？

如果转换函数里要查另一张表的当前状态（比如查 `token.token.eth` 拿 `decimals`），把这张表传给 `depends` 参数，`Pipeline` 会保证只有它也追平到当前高度才处理：

```python theme={null}
pipe = Pipeline(
    triggers=[...],
    target_table="...",
    depends=["token.token.eth"],
)
```

## 想要更精细的控制

`Pipeline` 是官方推荐的默认入口，覆盖了绝大多数场景。如果你需要绕开它、直接控制订阅循环或者任务提交细节，底层的 `Subscribe`、`Aligned`、`TaskBuilder` 等 API 见 [Python SDK 参考](/reference/sdk/blockx)。
