Skip to content

Commit be1f132

Browse files
authored
chore: tighten the condition to notify status update (#764)
* chore: tighten the condition to notify status update * docs: more updates to documentation
1 parent da86848 commit be1f132

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

examples/amazon_s3_embedding/main.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ def _main() -> None:
102102

103103
amazon_s3_text_embedding_flow.setup()
104104
with cocoindex.FlowLiveUpdater(amazon_s3_text_embedding_flow) as updater:
105-
updater.abort()
106-
updater.wait()
107-
108105
while True:
109106
updates = updater.next_status_updates()
110107
print(f"Updates: {updates}")

python/cocoindex/flow.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ async def wait_async(self) -> None:
604604
def next_status_updates(self) -> FlowUpdaterStatusUpdates:
605605
"""
606606
Get the next status updates.
607+
608+
It blocks until there's a new status updates, including the processing finishes for a bunch of source updates,
609+
and live updater stops (aborted, or no more sources to process).
607610
"""
608611
return execution_context.run(self.next_status_updates_async())
609612

src/execution/live_updater.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::prelude::*;
1+
use crate::{execution::stats::UpdateStats, prelude::*};
22

33
use super::stats;
44
use futures::future::try_join_all;
@@ -159,12 +159,18 @@ impl SourceUpdateTask {
159159
break;
160160
};
161161

162+
let update_stats = Arc::new(stats::UpdateStats::default());
162163
let ack_fn = {
163164
let status_tx = status_tx.clone();
165+
let update_stats = update_stats.clone();
166+
let change_stream_stats = change_stream_stats.clone();
164167
async move || {
165-
status_tx.send_modify(|update| {
166-
update.source_updates_num[source_idx] += 1;
167-
});
168+
if update_stats.has_any_change() {
169+
status_tx.send_modify(|update| {
170+
update.source_updates_num[source_idx] += 1;
171+
});
172+
change_stream_stats.merge(&update_stats);
173+
}
168174
if let Some(ack_fn) = change_msg.ack_fn {
169175
ack_fn().await
170176
} else {
@@ -185,7 +191,7 @@ impl SourceUpdateTask {
185191
tokio::spawn(source_context.clone().process_source_key(
186192
change.key,
187193
change.data,
188-
change_stream_stats.clone(),
194+
update_stats.clone(),
189195
concur_permit,
190196
Some(move || async move {
191197
SharedAckFn::ack(&shared_ack_fn).await
@@ -203,7 +209,8 @@ impl SourceUpdateTask {
203209
futs.push(
204210
async move {
205211
let mut interval = tokio::time::interval(REPORT_INTERVAL);
206-
let mut last_change_stream_stats = change_stream_stats.as_ref().clone();
212+
let mut last_change_stream_stats: UpdateStats =
213+
change_stream_stats.as_ref().clone();
207214
interval.set_missed_tick_behavior(MissedTickBehavior::Delay);
208215
interval.tick().await;
209216
loop {
@@ -229,9 +236,11 @@ impl SourceUpdateTask {
229236
async move {
230237
let update_stats = Arc::new(stats::UpdateStats::default());
231238
source_context.update(&pool, &update_stats).await?;
232-
status_tx.send_modify(|update| {
233-
update.source_updates_num[source_idx] += 1;
234-
});
239+
if update_stats.has_any_change() {
240+
status_tx.send_modify(|update| {
241+
update.source_updates_num[source_idx] += 1;
242+
});
243+
}
235244
report_stats(&update_stats, "batch update");
236245

237246
if let (true, Some(refresh_interval)) =
@@ -245,9 +254,11 @@ impl SourceUpdateTask {
245254

246255
let update_stats = Arc::new(stats::UpdateStats::default());
247256
source_context.update(&pool, &update_stats).await?;
248-
status_tx.send_modify(|update| {
249-
update.source_updates_num[source_idx] += 1;
250-
});
257+
if update_stats.has_any_change() {
258+
status_tx.send_modify(|update| {
259+
update.source_updates_num[source_idx] += 1;
260+
});
261+
}
251262
report_stats(&update_stats, "interval refresh");
252263
}
253264
}

0 commit comments

Comments
 (0)