Skip to content

Commit 85b3758

Browse files
committed
Send pending updates when a new slot is received
1 parent 3ebbdd9 commit 85b3758

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

pc/manager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,12 @@ void manager::on_response( rpc::get_slot *res )
746746
if (
747747
has_status( PC_PYTH_RPC_CONNECTED )
748748
) {
749+
750+
// New slot received, so flush all pending updates for all active users
751+
for( user *uptr = olist_.first(); uptr; uptr = uptr->get_next() ) {
752+
uptr->send_pending_upds();
753+
}
754+
749755
if ( sub_ ) {
750756
sub_->on_slot_publish( this );
751757
}

pc/user.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define PC_JSON_UNKNOWN_SYMBOL -32000
1212
#define PC_JSON_MISSING_PERMS -32001
1313
#define PC_JSON_NOT_READY -32002
14+
#define PC_BATCH_SEND_FAILED -32010
1415

1516
using namespace pc;
1617

@@ -326,6 +327,19 @@ void user::parse_get_product( uint32_t tok, uint32_t itok )
326327
add_tail( itok );
327328
}
328329

330+
void user::send_pending_upds()
331+
{
332+
if ( pending_vec_.empty() ) {
333+
return;
334+
}
335+
336+
if ( !price::send( pending_vec_.data(), pending_vec_.size()) ) {
337+
add_error( 0, PC_BATCH_SEND_FAILED, "batch send failed - please check the pyth logs" );
338+
}
339+
340+
pending_vec_.clear();
341+
}
342+
329343
void user::parse_get_all_products( uint32_t itok )
330344
{
331345
add_header();

pc/user.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ namespace pc
4343
// symbol price schedule callback
4444
void on_response( price_sched *, uint64_t ) override;
4545

46+
// send all pending updates
47+
void send_pending_upds();
48+
4649
private:
4750

4851
// http-only request parsing

0 commit comments

Comments
 (0)