Add app_state reload util and add handler for weekday change
This commit is contained in:
parent
97d9222a39
commit
6414083af0
5 changed files with 51 additions and 38 deletions
emgauwa-controller/src
|
@ -27,13 +27,22 @@ async fn run_relays(app_state: &Addr<AppState>) -> Result<(), EmgauwaError> {
|
|||
let default_duration = Duration::new(10, 0);
|
||||
let notifier = &*app_state_get_notifier(app_state).await?;
|
||||
|
||||
let mut last_weekday = emgauwa_lib::utils::get_weekday();
|
||||
let mut this = utils::app_state_get_this(app_state).await?;
|
||||
|
||||
loop {
|
||||
let notifier_future = notifier.notified();
|
||||
pin_mut!(notifier_future);
|
||||
let timeout_result = timeout(default_duration, &mut notifier_future).await;
|
||||
let changed = timeout_result.is_ok();
|
||||
let mut changed = timeout_result.is_ok();
|
||||
|
||||
let current_weekday = emgauwa_lib::utils::get_weekday();
|
||||
if current_weekday != last_weekday {
|
||||
log::debug!("Weekday changed");
|
||||
last_weekday = current_weekday;
|
||||
utils::app_state_reload(app_state).await?;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if changed {
|
||||
log::debug!("Reloading controller in relay loop");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue