2023-03-22 18:34:06 +00:00
|
|
|
// Code to handle the nebula worker
|
2023-03-21 17:00:01 +00:00
|
|
|
|
2023-03-23 17:17:37 +00:00
|
|
|
use std::sync::mpsc::{Receiver, TryRecvError};
|
|
|
|
use log::{error, info};
|
2023-03-30 11:29:02 +00:00
|
|
|
use crate::config::{load_cdata, save_cdata, TFClientConfig};
|
2023-03-22 18:34:06 +00:00
|
|
|
use crate::daemon::ThreadMessageSender;
|
|
|
|
|
|
|
|
pub enum NebulaWorkerMessage {
|
2023-03-29 22:44:46 +00:00
|
|
|
Shutdown,
|
|
|
|
ConfigUpdated
|
2023-03-22 18:34:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 11:29:02 +00:00
|
|
|
pub fn nebulaworker_main(_config: TFClientConfig, instance: String, _transmitter: ThreadMessageSender, rx: Receiver<NebulaWorkerMessage>) {
|
|
|
|
let cdata = match load_cdata(&instance) {
|
|
|
|
Ok(data) => data,
|
|
|
|
Err(e) => {
|
|
|
|
error!("unable to load cdata: {}", e);
|
|
|
|
error!("nebula thread exiting with error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// dont need to save it, because we do not, in any circumstance, write to it
|
2023-03-23 17:17:37 +00:00
|
|
|
loop {
|
|
|
|
match rx.try_recv() {
|
|
|
|
Ok(msg) => {
|
|
|
|
match msg {
|
|
|
|
NebulaWorkerMessage::Shutdown => {
|
|
|
|
info!("recv on command socket: shutdown, stopping");
|
|
|
|
break;
|
2023-03-29 22:44:46 +00:00
|
|
|
},
|
|
|
|
NebulaWorkerMessage::ConfigUpdated => {
|
|
|
|
info!("our configuration has been updated - reloading");
|
2023-03-23 17:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
match e {
|
|
|
|
TryRecvError::Empty => {}
|
|
|
|
TryRecvError::Disconnected => {
|
|
|
|
error!("nebulaworker command socket disconnected, shutting down to prevent orphaning");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 17:00:01 +00:00
|
|
|
}
|