Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 0e63eda

Browse files
committed
connect steps
1 parent 71e098a commit 0e63eda

File tree

5 files changed

+60
-25
lines changed

5 files changed

+60
-25
lines changed

apps/nextra/next.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ export default withBundleAnalyzer(
423423
destination: "/en/build/indexer/indexer-sdk/documentation/parsing-txns",
424424
permanent: true,
425425
},
426+
{
427+
source: "/indexer/indexer-sdk/documentation/connect-steps",
428+
destination:
429+
"/en/build/indexer/indexer-sdk/documentation/connect-steps",
430+
permanent: true,
431+
},
426432
{
427433
source: "/indexer/txn-stream/labs-hosted",
428434
destination: "/en/build/indexer/api/labs-hosted",

apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/_meta.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ export default {
99
"parsing-txns": {
1010
title: "Parsing Transactions",
1111
},
12+
"connect-steps": {
13+
title: "Connecting Steps",
14+
},
1215
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: "Connecting Steps"
3+
---
4+
5+
# Connecting Steps
6+
7+
## Pre-requisite
8+
At this point, you'd have already followed the [Creating a Processor](./create-processor.mdx) and [Creating a Step](./steps.mdx) guides.
9+
Our next goal is to put those two pieces together and connect steps within the processor.
10+
11+
## How to connect steps
12+
13+
Now that you have created a step, you can connect it to other steps.
14+
To do so, we use a builder class called `ProcessorBuilder` to specifiy a sequence of steps that make up a processor.
15+
16+
1. After you've instantiated your steps, you need to convert them into [`RunnableStep`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk/src/traits/runnable_step.rs#L6).
17+
`RunnableStep` is a trait that wraps around a step.
18+
It provides the necessary input and output channels that feed into the step and allows the step to be spawned in a task.
19+
The SDK provides a helper function [`.into_runnable_step`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk/src/traits/into_runnable_step.rs#L13) to convert a step into a `RunnableStep`.
20+
2. Setup your first step with [`ProcessorBuilder::new_with_inputless_first_step`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk/src/builder/processor_builder.rs#L222).
21+
In almost all cases, the first step should be a `TransactionStreamStep`. {/* <!-- Add link --> */}
22+
3. Connect the previous step to the next step using [`.connect_to`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk/src/builder/processor_builder.rs#L303).
23+
`connect_to` uses trait bounds to ensure at compile time that the output type of the previous step matches the input type of the next step.
24+
When calling `.connect_to`, a channel gets created with size `channel_size` and connects the previous and next steps.
25+
It also handles spawning the previous step in a task.
26+
4. Repeat step 3 for each step in your processor.
27+
5. To close off the `ProcessorBuilder`, use [`.end_and_return_output_receiver`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/sdk/src/builder/processor_builder.rs#L400).
28+
This return an [`InstrumentedAsyncReceiver`](https://github.com/aptos-labs/aptos-indexer-processor-sdk/blob/main/aptos-indexer-processors-sdk/instrumented-channel/src/lib.rs#L88) which you can use to process the output of the last step in the graph.
29+
30+
Here's a simple example of connecting two steps:
31+
```rust
32+
let (processor_builder, buffer_receiver) = ProcessorBuilder::new_with_inputless_first_step(
33+
transaction_stream_step.into_runnable_step(),
34+
)
35+
.connect_to(extractor_step.into_runnable_step(), 10)
36+
.end_and_return_output_receiver(10);
37+
```
38+
39+
Here's a [full example](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/aptos-indexer-processor-example/src/processors/events/events_processor.rs#L75) from `aptos-indexer-processor-example`.
40+
41+
{/* <!-- Add link to common SDK steps --> */}
42+
43+
## Visualizing the processor
44+
As you connect steps, `ProcessorBuilder` in the background is constructing a graphical representation of the steps in your processor using [`petgraph`](https://docs.rs/petgraph/latest/petgraph/).
45+
You can see the visual representation of the graph by calling
46+
```rust
47+
let dot = processor_builder.graph.dot();
48+
println!("{}", dot);
49+
```
50+
This will output a graph in the [DOT language](https://graphviz.gitlab.io/_pages/doc/info/lang.html) that you can visualize using tools like [Graphviz](https://graphviz.org/).

apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/create-processor.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ loop {
101101
}
102102
```
103103

104-
You can see a full example of a processor that indexes raw Aptos events in [`aptos-indexer-processor-example`](https://github.com/aptos-labs/aptos-indexer-processors/blob/main/rust/sdk-processor/src/processors/events_processor.rs).
104+
You can see a full example of a processor that indexes raw Aptos events in [`aptos-indexer-processor-example`](https://github.com/aptos-labs/aptos-indexer-processor-example/blob/main/aptos-indexer-processor-example/src/processors/events/events_processor.rs).
105105
As a reference, you can also see all of the processors that make up the [Indexer API](../../aptos-hosted.mdx) in [`aptos-indexer-processors`](https://github.com/aptos-labs/aptos-indexer-processors/tree/main/rust/sdk-processor/src/processors).
106106

107107
## How to define `main.rs`

apps/nextra/pages/en/build/indexer/indexer-sdk/documentation/steps.mdx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,6 @@ To create a step with the SDK, follow these instructions:
8787
}
8888
```
8989

90-
## How to connect steps
91-
92-
Now that you have created a step, you can connect it to other steps in the processor.
93-
`ProcessorBuilder` is used to connect a graph of steps to construct a processor.
94-
It uses trait bounds to ensure that the output type of each step matches the input type of its connected step.
95-
96-
### How to use `ProcessorBuilder`
97-
98-
1. Initialize the processor with the first step using `ProcessorBuilder::new_with_inputless_first_step`.
99-
2. Connect the next step using `.connect_to(second_step.into_runnable_step(), channel_size)`.
100-
- `.into_runnable_step()` converts your step into a `RunnableStep`, which enables it to store the step's input and output channels and allows the step to be spawned in a task.
101-
- When you use `.connect_to`, a channel gets created with size `channel_size` and connected to the previous and current steps, and the previous step is spawned in a task.
102-
3. To close off the `ProcessorBuilder`, use `.end_and_return_output_receiver(channel_size)`. This returns a channel receiver that can be used to receive the final output of the processor.
103-
104-
### Example
105-
```rust
106-
let (pb, buffer_receiver) = ProcessorBuilder::new_with_inputless_first_step(
107-
first_step.into_runnable_step(),
108-
)
109-
.connect_to(second_step.into_runnable_step(), channel_size)
110-
.connect_to(third_step.into_runnable_step(), channel_size)
111-
.end_and_return_output_receiver(channel_size);
112-
```
113-
11490
## Common steps
11591

11692
The SDK provides several common steps that you can use in your processor.

0 commit comments

Comments
 (0)