Private
Public Access
1
0

bugfixes, better handling of server url changes

This commit is contained in:
2025-06-13 17:11:29 -07:00
parent dece6f1abc
commit 45d873907f
5 changed files with 58 additions and 4 deletions

View File

@@ -15,10 +15,16 @@ use kordophone_db::database::DatabaseAccess;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::mpsc::Sender;
use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::Mutex;
pub enum UpdateMonitorCommand {
Restart,
}
pub struct UpdateMonitor {
command_tx: Option<Sender<UpdateMonitorCommand>>,
command_rx: Receiver<UpdateMonitorCommand>,
database: Arc<Mutex<Database>>,
event_sender: Sender<Event>,
last_sync_times: HashMap<String, Instant>,
@@ -28,16 +34,23 @@ pub struct UpdateMonitor {
impl UpdateMonitor {
pub fn new(database: Arc<Mutex<Database>>, event_sender: Sender<Event>) -> Self {
let (command_tx, command_rx) = tokio::sync::mpsc::channel(1);
Self {
database,
event_sender,
last_sync_times: HashMap::new(),
update_seq: None,
first_connection: false, // optimistic assumption that we're not reconnecting the first time.
command_tx: Some(command_tx),
command_rx,
}
}
pub async fn send_event<T>(
pub fn take_command_channel(&mut self) -> Sender<UpdateMonitorCommand> {
self.command_tx.take().unwrap()
}
async fn send_event<T>(
&self,
make_event: impl FnOnce(Reply<T>) -> Event,
) -> DaemonResult<T> {
@@ -201,6 +214,15 @@ impl UpdateMonitor {
}
}
}
Some(command) = self.command_rx.recv() => {
match command {
UpdateMonitorCommand::Restart => {
log::info!(target: target::UPDATES, "Restarting update monitor");
break;
}
}
}
}
}