11use std:: collections:: BTreeMap ;
22use std:: pin:: Pin ;
33use std:: sync:: Arc ;
4- use std:: sync:: atomic:: AtomicBool ;
4+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
55
66use futures:: channel:: mpsc:: { UnboundedSender , unbounded} ;
77use log:: info;
@@ -89,6 +89,21 @@ impl From<AlarmWithTimestamp> for RpcValue {
8989 }
9090}
9191
92+ pub ( crate ) struct ReloadGuard < ' a > ( & ' a AtomicBool ) ;
93+
94+ impl < ' a > ReloadGuard < ' a > {
95+ pub ( crate ) fn new ( flag : & ' a AtomicBool ) -> Self {
96+ flag. store ( true , Ordering :: Relaxed ) ;
97+ ReloadGuard ( flag)
98+ }
99+ }
100+
101+ impl Drop for ReloadGuard < ' _ > {
102+ fn drop ( & mut self ) {
103+ self . 0 . store ( false , Ordering :: Relaxed ) ;
104+ }
105+ }
106+
92107pub struct State {
93108 start_time : std:: time:: Instant ,
94109 sites_data : RwLock < sites:: SitesData > ,
@@ -100,6 +115,8 @@ pub struct State {
100115 sync_cmd_tx : DedupSender < sync:: SyncCommand > ,
101116 dirtylog_cmd_tx : UnboundedSender < dirtylog:: DirtyLogCommand > ,
102117 app_closing : AtomicBool ,
118+ last_sites_loaded : RwLock < Option < std:: time:: Instant > > ,
119+ pub ( crate ) sites_reload_in_progress : AtomicBool ,
103120}
104121
105122#[ derive( Default ) ]
@@ -135,6 +152,7 @@ pub fn make_client(hp_config: &HpConfig, tasks: &mut AppTasks) -> shvrpc::Result
135152
136153 let ( sync_cmd_tx, sync_cmd_rx) = crate :: util:: dedup_channel ( ) ;
137154 let ( dirtylog_cmd_tx, dirtylog_cmd_rx) = unbounded ( ) ;
155+ let ( sites_cmd_tx, sites_cmd_rx) = unbounded ( ) ;
138156
139157 let app_state = Arc :: new ( State {
140158 start_time : std:: time:: Instant :: now ( ) ,
@@ -147,13 +165,15 @@ pub fn make_client(hp_config: &HpConfig, tasks: &mut AppTasks) -> shvrpc::Result
147165 sync_cmd_tx,
148166 dirtylog_cmd_tx,
149167 app_closing : AtomicBool :: new ( false ) ,
168+ last_sites_loaded : RwLock :: new ( None ) ,
169+ sites_reload_in_progress : AtomicBool :: new ( false ) ,
150170 } ) ;
151171
152172 let client = shvclient:: Client :: new ( )
153173 . mount_dynamic ( "" , {
154174 let app_state = app_state. clone ( ) ;
155175 move |rq, cmd_sender|
156- tree:: request_handler ( rq, cmd_sender, app_state. clone ( ) )
176+ tree:: request_handler ( rq, cmd_sender, sites_cmd_tx . clone ( ) , app_state. clone ( ) )
157177 } ) ;
158178
159179 let init_function = {
@@ -183,7 +203,7 @@ pub fn make_client(hp_config: &HpConfig, tasks: &mut AppTasks) -> shvrpc::Result
183203 handle_signal ( SignalKind :: interrupt ( ) ) ;
184204 handle_signal ( SignalKind :: terminate ( ) ) ;
185205
186- tasks. sites_task = Some ( wrap_task ( tokio:: spawn ( sites:: sites_task ( client_cmd_tx. clone ( ) , client_evt_rx. clone ( ) , app_state. clone ( ) ) ) ) ) ;
206+ tasks. sites_task = Some ( wrap_task ( tokio:: spawn ( sites:: sites_task ( client_cmd_tx. clone ( ) , client_evt_rx. clone ( ) , app_state. clone ( ) , sites_cmd_rx ) ) ) ) ;
187207 tasks. sync_task = Some ( wrap_task ( tokio:: spawn ( sync:: sync_task ( client_cmd_tx. clone ( ) , client_evt_rx. clone ( ) , app_state. clone ( ) , sync_cmd_rx) ) ) ) ;
188208 tasks. dirtylog_task = Some ( wrap_task ( tokio:: spawn ( dirtylog:: dirtylog_task ( client_cmd_tx, client_evt_rx, app_state. clone ( ) , dirtylog_cmd_rx) ) ) ) ;
189209 }
0 commit comments