Stop using the syncer with the fetcher; Remove the syncer

This commit is contained in:
Mike Dilger 2023-01-01 12:18:27 +13:00
parent 26141a27d1
commit f28ae0d9c6
4 changed files with 6 additions and 64 deletions

View File

@ -105,7 +105,12 @@ impl Fetcher {
// We can't fetch as we are not async and we don't want to block the caller. // We can't fetch as we are not async and we don't want to block the caller.
// So we save this request as pending, and ask the syncer to sync us. // So we save this request as pending, and ask the syncer to sync us.
self.pending.write().unwrap().insert(url); self.pending.write().unwrap().insert(url);
let _ = GLOBALS.to_syncer.send("sync_fetcher".to_owned()); tokio::spawn(async move {
if let Err(e) = GLOBALS.fetcher.sync().await {
tracing::error!("Problem fetching from web: {}", e);
}
});
Ok(None) Ok(None)
} }

View File

@ -32,14 +32,6 @@ pub struct Globals {
/// and stolen away when the Overlord is created. /// and stolen away when the Overlord is created.
pub tmp_overlord_receiver: Mutex<Option<mpsc::UnboundedReceiver<BusMessage>>>, pub tmp_overlord_receiver: Mutex<Option<mpsc::UnboundedReceiver<BusMessage>>>,
/// This is an mpsc channel. The Syncer listens on it.
/// To create a sender, just clone() it.
pub to_syncer: mpsc::UnboundedSender<String>,
/// This is ephemeral. It is filled during lazy_static initializtion,
/// and stolen away when the Syncer is created.
pub tmp_syncer_receiver: Mutex<Option<mpsc::UnboundedReceiver<String>>>,
/// All nostr events, keyed by the event Id /// All nostr events, keyed by the event Id
pub events: RwLock<HashMap<Id, Event>>, pub events: RwLock<HashMap<Id, Event>>,
@ -95,16 +87,11 @@ lazy_static! {
// Setup a communications channel from the Minions to the Overlord. // Setup a communications channel from the Minions to the Overlord.
let (to_overlord, tmp_overlord_receiver) = mpsc::unbounded_channel(); let (to_overlord, tmp_overlord_receiver) = mpsc::unbounded_channel();
// Setup a communications channel from the UI (or anybody else) to the Syncer.
let (to_syncer, tmp_syncer_receiver) = mpsc::unbounded_channel();
Globals { Globals {
db: Mutex::new(None), db: Mutex::new(None),
to_minions, to_minions,
to_overlord, to_overlord,
tmp_overlord_receiver: Mutex::new(Some(tmp_overlord_receiver)), tmp_overlord_receiver: Mutex::new(Some(tmp_overlord_receiver)),
to_syncer,
tmp_syncer_receiver: Mutex::new(Some(tmp_syncer_receiver)),
events: RwLock::new(HashMap::new()), events: RwLock::new(HashMap::new()),
incoming_events: RwLock::new(Vec::new()), incoming_events: RwLock::new(Vec::new()),
relationships: RwLock::new(HashMap::new()), relationships: RwLock::new(HashMap::new()),

View File

@ -17,7 +17,6 @@ mod process;
mod relationship; mod relationship;
mod settings; mod settings;
mod signer; mod signer;
mod syncer;
mod ui; mod ui;
use crate::comms::BusMessage; use crate::comms::BusMessage;
@ -75,20 +74,6 @@ fn main() -> Result<(), Error> {
} }
async fn tokio_main() { async fn tokio_main() {
// note: we don't get a spawn handle here, we don't signal this thread when we are exiting,
// we just let it die when tokio_main() exits. I think that is ok.
tokio::task::spawn(async move {
// Steal `tmp_syncer_receiver` from the GLOBALS, and give it to a new Syncer
let syncer_receiver = {
let mut mutex_option = GLOBALS.tmp_syncer_receiver.lock().await;
mem::replace(mutex_option.deref_mut(), None)
}
.unwrap();
let mut syncer = crate::syncer::Syncer::new(syncer_receiver);
syncer.run().await;
});
// Steal `tmp_overlord_receiver` from the GLOBALS, and give it to a new Overlord // Steal `tmp_overlord_receiver` from the GLOBALS, and give it to a new Overlord
let overlord_receiver = { let overlord_receiver = {
let mut mutex_option = GLOBALS.tmp_overlord_receiver.lock().await; let mut mutex_option = GLOBALS.tmp_overlord_receiver.lock().await;

View File

@ -1,35 +0,0 @@
use crate::globals::GLOBALS;
use tokio::sync::mpsc;
pub struct Syncer {
incoming: mpsc::UnboundedReceiver<String>,
}
impl Syncer {
pub fn new(incoming: mpsc::UnboundedReceiver<String>) -> Syncer {
Syncer { incoming }
}
pub async fn run(&mut self) {
loop {
let message = self.incoming.recv().await;
if message.is_none() {
return;
}
let message = message.unwrap();
match &*message {
"sync_fetcher" => {
if let Err(e) = GLOBALS.fetcher.sync().await {
tracing::error!("Problem fetching from web: {}", e);
}
}
_ => {
tracing::debug!("Syncer received unknown message: {}", message);
}
}
}
}
}