mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Bring over some overlord minion-exit handling we forgot from the tauri branch
This commit is contained in:
parent
a9a4688b7e
commit
79d2e2ca3a
@ -13,13 +13,16 @@ use std::collections::HashMap;
|
|||||||
use tokio::sync::broadcast::Sender;
|
use tokio::sync::broadcast::Sender;
|
||||||
use tokio::sync::mpsc::UnboundedReceiver;
|
use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
use tokio::{select, task};
|
use tokio::{select, task};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info, warn};
|
||||||
|
|
||||||
pub struct Overlord {
|
pub struct Overlord {
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
to_minions: Sender<BusMessage>,
|
to_minions: Sender<BusMessage>,
|
||||||
from_minions: UnboundedReceiver<BusMessage>,
|
from_minions: UnboundedReceiver<BusMessage>,
|
||||||
|
|
||||||
|
// All the minion tasks running.
|
||||||
minions: task::JoinSet<()>,
|
minions: task::JoinSet<()>,
|
||||||
|
|
||||||
minions_task_url: HashMap<task::Id, Url>,
|
minions_task_url: HashMap<task::Id, Url>,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
private_key: Option<PrivateKey>, // note that PrivateKey already zeroizes on drop
|
private_key: Option<PrivateKey>, // note that PrivateKey already zeroizes on drop
|
||||||
@ -217,6 +220,44 @@ impl Overlord {
|
|||||||
};
|
};
|
||||||
keepgoing = self.handle_bus_message(bus_message).await?;
|
keepgoing = self.handle_bus_message(bus_message).await?;
|
||||||
},
|
},
|
||||||
|
task_next_joined = self.minions.join_next_with_id() => {
|
||||||
|
if task_next_joined.is_none() {
|
||||||
|
return Ok(true); // rare but possible
|
||||||
|
}
|
||||||
|
match task_next_joined.unwrap() {
|
||||||
|
Err(join_error) => {
|
||||||
|
let id = join_error.id();
|
||||||
|
let maybe_url = self.minions_task_url.get(&id);
|
||||||
|
match maybe_url {
|
||||||
|
Some(url) => {
|
||||||
|
// JoinError also has is_cancelled, is_panic, into_panic, try_into_panic
|
||||||
|
// Minion probably alreaedy logged, this may be redundant.
|
||||||
|
warn!("Minion {} completed with error: {}", &url, join_error);
|
||||||
|
|
||||||
|
// Minion probably already logged failure in relay table
|
||||||
|
|
||||||
|
// Remove from our hashmap
|
||||||
|
self.minions_task_url.remove(&id);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
warn!("Minion UNKNOWN completed with error: {}", join_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok((id, _)) => {
|
||||||
|
let maybe_url = self.minions_task_url.get(&id);
|
||||||
|
match maybe_url {
|
||||||
|
Some(url) => {
|
||||||
|
warn!("Relay Task {} completed", &url);
|
||||||
|
|
||||||
|
// Remove from our hashmap
|
||||||
|
self.minions_task_url.remove(&id);
|
||||||
|
},
|
||||||
|
None => warn!("Relay Task UNKNOWN completed"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(keepgoing)
|
Ok(keepgoing)
|
||||||
@ -244,6 +285,7 @@ impl Overlord {
|
|||||||
"overlord" => match &*bus_message.kind {
|
"overlord" => match &*bus_message.kind {
|
||||||
"minion_is_ready" => {}
|
"minion_is_ready" => {}
|
||||||
"save_settings" => {
|
"save_settings" => {
|
||||||
|
// from ui
|
||||||
let settings: Settings = serde_json::from_str(&bus_message.json_payload)?;
|
let settings: Settings = serde_json::from_str(&bus_message.json_payload)?;
|
||||||
|
|
||||||
// Save to database
|
// Save to database
|
||||||
|
Loading…
Reference in New Issue
Block a user