Skip to content

Commit 478ba0d

Browse files
committed
store: Asyncify notification_listener
1 parent 8e11d1f commit 478ba0d

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

store/postgres/src/chain_head_listener.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,21 @@ impl ChainHeadUpdateSender {
254254
}
255255
}
256256

257-
pub fn send(&self, hash: &str, number: i64) -> Result<(), StoreError> {
257+
pub async fn send(&self, hash: &str, number: i64) -> Result<(), StoreError> {
258258
let msg = json! ({
259259
"network_name": &self.chain_name,
260260
"head_block_hash": hash,
261261
"head_block_number": number
262262
});
263263

264264
let mut conn = self.pool.get()?;
265-
self.sender.notify(
266-
&mut conn,
267-
CHANNEL_NAME.as_str(),
268-
Some(&self.chain_name),
269-
&msg,
270-
)
265+
self.sender
266+
.notify(
267+
&mut conn,
268+
CHANNEL_NAME.as_str(),
269+
Some(&self.chain_name),
270+
&msg,
271+
)
272+
.await
271273
}
272274
}

store/postgres/src/chain_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ impl ChainHeadStore for ChainStore {
22762276
let number = ptr.number as i64; //block height
22772277

22782278
//this will send an update via postgres, channel: chain_head_updates
2279-
self.chain_head_update_sender.send(&hash, number)?;
2279+
self.chain_head_update_sender.send(&hash, number).await?;
22802280

22812281
pool.with_conn(async move |conn, _| {
22822282
conn.transaction_async(|conn| {
@@ -2412,7 +2412,7 @@ impl ChainStoreTrait for ChainStore {
24122412
.await?
24132413
};
24142414
if let Some((hash, number)) = ptr {
2415-
self.chain_head_update_sender.send(&hash, number)?;
2415+
self.chain_head_update_sender.send(&hash, number).await?;
24162416
}
24172417

24182418
Ok(missing)

store/postgres/src/notification_listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl NotificationSender {
404404
/// connection `conn` must be into the primary database as that's the
405405
/// only place where listeners connect. The `network` is only used for
406406
/// metrics gathering and does not affect how the notification is sent
407-
pub fn notify(
407+
pub async fn notify(
408408
&self,
409409
conn: &mut PgConnection,
410410
channel: &str,

store/postgres/src/primary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,9 @@ impl Connection {
15391539
EVENT_TAP.lock().unwrap().push(event.clone());
15401540
}
15411541
}
1542-
sender.notify(&mut self.conn, "store_events", None, &v)
1542+
sender
1543+
.notify(&mut self.conn, "store_events", None, &v)
1544+
.await
15431545
}
15441546

15451547
/// Return the name of the node that has the fewest assignments out of the

0 commit comments

Comments
 (0)