Skip to content

Commit 05d56f8

Browse files
Track timestamps in lazer_exporter to avoid duplicate messages
Keep track of the most recent PriceInfo::timestamp for each pyth_sdk::Identifier and skip objects that do not have a newer timestamp. This prevents sending duplicate FeedUpdate messages when the local state has not been updated. Co-Authored-By: Mike Rolish <merolish@mit.edu>
1 parent 5e8d070 commit 05d56f8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/agent/services/lazer_exporter.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ mod lazer_exporter {
420420
// consume immediate tick
421421
publish_interval.tick().await;
422422

423+
let mut last_sent_timestamps: HashMap<pyth_sdk::Identifier, chrono::NaiveDateTime> = HashMap::new();
424+
423425
loop {
424426
tokio::select! {
425427
_ = publish_interval.tick() => {
@@ -434,6 +436,12 @@ mod lazer_exporter {
434436
// TODO: This read locks and clones local::Store::prices, which may not meet performance needs.
435437
for (identifier, price_info) in state.get_all_price_infos().await {
436438
if let Some(symbol) = lazer_symbols.get(&identifier) {
439+
if let Some(last_timestamp) = last_sent_timestamps.get(&identifier) {
440+
if price_info.timestamp <= *last_timestamp {
441+
continue;
442+
}
443+
}
444+
437445
let source_timestamp_micros = price_info.timestamp.and_utc().timestamp_micros();
438446
let source_timestamp = MessageField::some(Timestamp {
439447
seconds: source_timestamp_micros / 1_000_000,
@@ -449,7 +457,8 @@ mod lazer_exporter {
449457
..PriceUpdate::default()
450458
})),
451459
special_fields: Default::default(),
452-
})
460+
});
461+
last_sent_timestamps.insert(identifier, price_info.timestamp);
453462
}
454463
}
455464

0 commit comments

Comments
 (0)