@@ -50,14 +50,19 @@ use {
5050 } ,
5151 sync:: Arc ,
5252 time:: {
53- Duration ,
5453 SystemTime ,
5554 UNIX_EPOCH ,
5655 } ,
5756 } ,
58- tokio:: sync:: {
59- mpsc:: Sender ,
60- RwLock ,
57+ tokio:: {
58+ sync:: {
59+ mpsc:: Sender ,
60+ RwLock ,
61+ } ,
62+ time:: {
63+ Duration ,
64+ Instant ,
65+ } ,
6166 } ,
6267 wormhole_sdk:: {
6368 Address ,
@@ -72,10 +77,11 @@ pub mod types;
7277pub mod wormhole;
7378
7479pub struct Store {
75- pub storage : StorageInstance ,
76- pub observed_vaa_seqs : Cache < u64 , bool > ,
77- pub guardian_set : RwLock < BTreeMap < u32 , GuardianSet > > ,
78- pub update_tx : Sender < ( ) > ,
80+ pub storage : StorageInstance ,
81+ pub observed_vaa_seqs : Cache < u64 , bool > ,
82+ pub guardian_set : RwLock < BTreeMap < u32 , GuardianSet > > ,
83+ pub update_tx : Sender < ( ) > ,
84+ pub last_completed_update_at : RwLock < Option < Instant > > ,
7985}
8086
8187impl Store {
@@ -88,6 +94,7 @@ impl Store {
8894 . build ( ) ,
8995 guardian_set : RwLock :: new ( Default :: default ( ) ) ,
9096 update_tx,
97+ last_completed_update_at : RwLock :: new ( None ) ,
9198 } )
9299 }
93100
@@ -168,6 +175,11 @@ impl Store {
168175
169176 self . update_tx . send ( ( ) ) . await ?;
170177
178+ self . last_completed_update_at
179+ . write ( )
180+ . await
181+ . replace ( Instant :: now ( ) ) ;
182+
171183 Ok ( ( ) )
172184 }
173185
@@ -256,4 +268,16 @@ impl Store {
256268 . map ( |key| PriceIdentifier :: new ( key. id ) )
257269 . collect ( )
258270 }
271+
272+ pub async fn is_healthy ( & self ) -> bool {
273+ const STALENESS_THRESHOLD : Duration = Duration :: from_secs ( 30 ) ;
274+
275+ let last_completed_update_at = self . last_completed_update_at . read ( ) . await ;
276+ match last_completed_update_at. as_ref ( ) {
277+ Some ( last_completed_update_at) => {
278+ last_completed_update_at. elapsed ( ) < STALENESS_THRESHOLD
279+ }
280+ None => false ,
281+ }
282+ }
259283}
0 commit comments