feat: spawn docker updates into own thread

Collects spawns into a hashmap, then on next update if spawn exists in hash map, don't bother to run another update
This commit is contained in:
Jack Wills
2022-07-23 02:46:38 +00:00
parent f5504c47c5
commit d0f617820c
7 changed files with 128 additions and 83 deletions
+5 -17
View File
@@ -10,7 +10,7 @@ use super::Header;
#[derive(Debug, Clone)]
pub struct StatefulList<T> {
pub state: ListState,
// HASH MAP!
// todo BTreeMap
pub items: Vec<T>,
}
@@ -84,7 +84,6 @@ impl<T> StatefulList<T> {
}
/// States of the container
// / impl ord
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub enum State {
Dead,
@@ -96,17 +95,6 @@ pub enum State {
Unknown,
}
// impl Ord for State {
// fn cmp(&self, other: &Self) -> Ordering {
// match (self, other) {
// (Self::Dead)
// // (_, Foo::B) => Ordering::Less,
// // (Foo::A { val: l }, Foo::A { val: r }) => l.cmp(&r),
// // (Foo::B, _) => Ordering::Greater,
// }
// }
// }
impl State {
pub fn get_color(&self) -> Color {
match self {
@@ -331,8 +319,8 @@ pub struct ContainerItem {
pub mem_limit: ByteStats,
pub mem_stats: VecDeque<ByteStats>,
pub name: String,
pub net_rx: ByteStats,
pub net_tx: ByteStats,
pub rx: ByteStats,
pub tx: ByteStats,
pub state: State,
pub status: String,
}
@@ -355,8 +343,8 @@ impl ContainerItem {
mem_limit: ByteStats::new(0),
mem_stats: VecDeque::with_capacity(60),
name,
net_rx: ByteStats::new(0),
net_tx: ByteStats::new(0),
rx: ByteStats::new(0),
tx: ByteStats::new(0),
state,
status,
}
+14 -26
View File
@@ -233,24 +233,12 @@ impl AppData {
SortedOrder::Desc => self.containers.items.sort_by(|a, b| b.name.cmp(&a.name)),
},
Header::Rx => match so {
SortedOrder::Asc => self
.containers
.items
.sort_by(|a, b| a.net_rx.cmp(&b.net_rx)),
SortedOrder::Desc => self
.containers
.items
.sort_by(|a, b| b.net_rx.cmp(&a.net_rx)),
SortedOrder::Asc => self.containers.items.sort_by(|a, b| a.rx.cmp(&b.rx)),
SortedOrder::Desc => self.containers.items.sort_by(|a, b| b.rx.cmp(&a.rx)),
},
Header::Tx => match so {
SortedOrder::Asc => self
.containers
.items
.sort_by(|a, b| a.net_tx.cmp(&b.net_tx)),
SortedOrder::Desc => self
.containers
.items
.sort_by(|a, b| b.net_tx.cmp(&a.net_tx)),
SortedOrder::Asc => self.containers.items.sort_by(|a, b| a.tx.cmp(&b.tx)),
SortedOrder::Desc => self.containers.items.sort_by(|a, b| b.tx.cmp(&a.tx)),
},
}
}
@@ -341,8 +329,8 @@ impl AppData {
container.mem_limit
));
let net_rx_count = count(&container.net_rx.to_string());
let net_tx_count = count(&container.net_tx.to_string());
let net_rx_count = count(&container.rx.to_string());
let net_tx_count = count(&container.tx.to_string());
let image_count = count(&container.image);
let name_count = count(&container.name);
let state_count = count(&container.state.to_string());
@@ -415,8 +403,8 @@ impl AppData {
container.mem_stats.push_back(ByteStats::new(mem));
}
container.net_rx.update(rx);
container.net_tx.update(tx);
container.rx.update(rx);
container.tx.update(tx);
container.mem_limit.update(mem_limit);
}
}
@@ -527,10 +515,10 @@ impl AppData {
self.logs_parsed = true;
}
/// Update all containers logs, should only be used on first initialisation
pub fn update_all_logs(&mut self, all_logs: Vec<Vec<String>>) {
for (index, output) in all_logs.into_iter().enumerate() {
self.update_log_by_index(output, index);
}
}
// /// Update all containers logs, should only be used on first initialisation
// pub fn update_all_logs(&mut self, all_logs: Vec<Vec<String>>) {
// for (index, output) in all_logs.into_iter().enumerate() {
// self.update_log_by_index(output, index);
// }
// }
}