Skip to content

Commit 981ebb1

Browse files
authored
docs: for FlowLiveUpdater to accomodate latest async/start change (#467)
1 parent 61d1ed6 commit 981ebb1

File tree

1 file changed

+47
-18
lines changed

1 file changed

+47
-18
lines changed

docs/docs/core/flow_methods.mdx

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
title: Flow Running
3+
toc_max_heading_level: 4
34
description: Run a CocoIndex Flow, including build / update data in the target storage and evaluate the flow without changing the target storage.
45
---
56

@@ -70,8 +71,7 @@ This is to achieve best efficiency.
7071

7172
### One time update
7273

73-
<Tabs queryString="code_lang">
74-
<TabItem value="shell" label="Shell" default>
74+
#### CLI
7575

7676
The `cocoindex update` subcommand creates/updates data in the target storage.
7777

@@ -81,7 +81,9 @@ Once it's done, the target data is fresh up to the moment when the function is c
8181
python main.py cocoindex update
8282
```
8383

84-
</TabItem>
84+
#### Library API
85+
86+
<Tabs>
8587
<TabItem value="python" label="Python">
8688

8789
The `update()` async method creates/updates data in the target storage.
@@ -108,8 +110,7 @@ A data source may enable one or multiple *change capture mechanisms*:
108110

109111
Change capture mechanisms enable CocoIndex to continuously capture changes from the source data and update the target data accordingly, under live update mode.
110112

111-
<Tabs queryString="code_lang">
112-
<TabItem value="shell" label="Shell" default>
113+
#### CLI
113114

114115
To perform live update, run the `cocoindex update` subcommand with `-L` option:
115116

@@ -120,7 +121,9 @@ python main.py cocoindex update -L
120121
If there's at least one data source with change capture mechanism enabled, it will keep running until the aborted (e.g. by `Ctrl-C`).
121122
Otherwise, it falls back to the same behavior as one time update, and will finish after a one-time update is done.
122123

123-
</TabItem>
124+
#### Library API
125+
126+
<Tabs>
124127
<TabItem value="python" label="Python">
125128

126129
To perform live update, you need to create a `cocoindex.FlowLiveUpdater` object using the `cocoindex.Flow` object.
@@ -145,15 +148,19 @@ my_updater = cocoindex.FlowLiveUpdater(
145148

146149
A `FlowLiveUpdater` object supports the following methods:
147150

151+
* `start()`: Start the updater.
152+
CocoIndex will continuously capture changes from the source data and update the target data accordingly in background threads managed by the engine.
148153
* `abort()`: Abort the updater.
149-
* `wait()` (async): Wait for the updater to finish. It only unblocks in one of the following cases:
154+
* `wait()`: Wait for the updater to finish. It only unblocks in one of the following cases:
150155
* The updater was aborted.
151156
* A one time update is done, and live update is not enabled:
152157
either `live_mode` is `False`, or all data sources have no change capture mechanisms enabled.
153158
* `update_stats()`: It returns the stats of the updater.
154159

155160
```python
156161
my_updater = cocoindex.FlowLiveUpdater(demo_flow)
162+
# Start the updater.
163+
my_updater.start()
157164

158165
# Perform your own logic (e.g. a query loop).
159166
...
@@ -163,26 +170,47 @@ print(my_updater.update_stats())
163170
# Abort the updater.
164171
my_updater.abort()
165172
# Wait for the updater to finish.
166-
await my_updater.wait()
173+
my_updater.wait()
167174
```
168175

169176
Python SDK also allows you to use the updater as a context manager.
170-
It will abort and wait for the updater to finish automatically when the context is exited.
171-
The following code is equivalent to the code above:
177+
It will automatically start the updater during the context entry, and abort and wait for the updater to finish automatically when the context is exited.
178+
The following code is equivalent to the code above (if no early return happens):
172179

173180
```python
174-
async with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
181+
with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
175182
# Perform your own logic (e.g. a query loop).
176183
...
177184
print(my_updater.update_stats())
178185
```
179186

180-
Within a synchronous function, remove `async` before `with`, like this:
187+
CocoIndex also provides asynchronous versions of APIs for blocking operations, including:
181188

182-
```python
183-
with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
189+
* `start_async()` and `wait_async()`, e.g.
190+
191+
```python
192+
my_updater = cocoindex.FlowLiveUpdater(demo_flow)
193+
# Start the updater.
194+
await my_updater.start_async()
195+
196+
# Perform your own logic (e.g. a query loop).
184197
...
185-
```
198+
199+
# Print the update stats.
200+
print(my_updater.update_stats())
201+
# Abort the updater.
202+
my_updater.abort()
203+
# Wait for the updater to finish.
204+
await my_updater.wait_async()
205+
```
206+
* Async context manager, e.g.
207+
208+
```python
209+
async with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
210+
# Perform your own logic (e.g. a query loop).
211+
...
212+
print(my_updater.update_stats())
213+
```
186214

187215
</TabItem>
188216
</Tabs>
@@ -191,8 +219,7 @@ with cocoindex.FlowLiveUpdater(demo_flow) as my_updater:
191219

192220
CocoIndex allows you to run the transformations defined by the flow without updating the target storage.
193221

194-
<Tabs queryString="code_lang">
195-
<TabItem value="shell" label="Shell" default>
222+
### CLI
196223

197224
The `cocoindex evaluate` subcommand runs the transformation and dumps flow outputs.
198225
It takes the following options:
@@ -208,7 +235,9 @@ Example:
208235
python main.py cocoindex evaluate --output-dir ./eval_output
209236
```
210237

211-
</TabItem>
238+
### Library API
239+
240+
<Tabs>
212241
<TabItem value="python" label="Python">
213242

214243
The `evaluate_and_dump()` method runs the transformation and dumps flow outputs to files.

0 commit comments

Comments
 (0)