Shutdown logic & Panel
This commit is contained in:
parent
e24b65833a
commit
0ec6159365
7 changed files with 46 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::APP_STATE;
|
use crate::APP_STATE;
|
||||||
|
use crate::SHUTDOWN;
|
||||||
use crate::gui::ratatui_interface::TERMINAL;
|
use crate::gui::ratatui_interface::TERMINAL;
|
||||||
use crate::gui::widgets::betterblock::draw_block_joins;
|
use crate::gui::widgets::betterblock::draw_block_joins;
|
||||||
use crate::langu::language_manager::format;
|
use crate::langu::language_manager::format;
|
||||||
|
|
@ -80,12 +81,15 @@ fn downsample_to_fit_width(data: &[(f64, f64)], width: u16) -> Vec<(f64, f64)> {
|
||||||
|
|
||||||
pub fn setup() {
|
pub fn setup() {
|
||||||
// Start a background thread to sample metrics
|
// Start a background thread to sample metrics
|
||||||
thread::spawn(move || {
|
thread::spawn(async move || {
|
||||||
let mut sys = System::new_with_specifics(RefreshKind::new());
|
let mut sys = System::new_with_specifics(RefreshKind::new());
|
||||||
let mut last_total_received = 0u64;
|
let mut last_total_received = 0u64;
|
||||||
let mut last_total_transmitted = 0u64;
|
let mut last_total_transmitted = 0u64;
|
||||||
let mut counter = 0.0;
|
let mut counter = 0.0;
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
|
|
||||||
let mut tcpu = 0;
|
let mut tcpu = 0;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::gui::nav_bar::NavBar;
|
use crate::{SHUTDOWN, gui::nav_bar::NavBar};
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
execute,
|
execute,
|
||||||
|
|
@ -39,6 +39,9 @@ fn init_terminal() {
|
||||||
async fn run() -> Result<()> {
|
async fn run() -> Result<()> {
|
||||||
init_terminal();
|
init_terminal();
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
NAV_BAR.lock().await.current_screen.renderf();
|
NAV_BAR.lock().await.current_screen.renderf();
|
||||||
tokio::time::sleep(Duration::from_millis(1000)).await;
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ use std::sync::LazyLock;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio::time::{Duration, sleep};
|
use tokio::time::{Duration, sleep};
|
||||||
|
use tower::make::AsService;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
mod auth;
|
mod auth;
|
||||||
|
|
@ -128,6 +129,9 @@ async fn main() {
|
||||||
.await;*/
|
.await;*/
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let omikron: Arc<OmikronConnection> = Arc::new(OmikronConnection::new());
|
let omikron: Arc<OmikronConnection> = Arc::new(OmikronConnection::new());
|
||||||
omikron.connect().await;
|
omikron.connect().await;
|
||||||
omikron
|
omikron
|
||||||
|
|
@ -148,6 +152,9 @@ async fn main() {
|
||||||
*omikron_connection = Some(omikron.clone());
|
*omikron_connection = Some(omikron.clone());
|
||||||
log_message_trans("setup_completed");
|
log_message_trans("setup_completed");
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if !omikron.is_connected().await {
|
if !omikron.is_connected().await {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::SHUTDOWN;
|
||||||
use crate::auth::local_auth;
|
use crate::auth::local_auth;
|
||||||
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
||||||
use crate::gui::log_panel::{log_cv, log_message, log_message_trans};
|
use crate::gui::log_panel::{log_cv, log_message, log_message_trans};
|
||||||
|
|
@ -87,6 +88,9 @@ impl OmikronConnection {
|
||||||
/// Connect loop with retry
|
/// Connect loop with retry
|
||||||
pub async fn connect(self: &Arc<Self>) {
|
pub async fn connect(self: &Arc<Self>) {
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
match connect_async("wss://app.tensamin.net/ws/iota/").await {
|
match connect_async("wss://app.tensamin.net/ws/iota/").await {
|
||||||
Ok((ws_stream, _)) => {
|
Ok((ws_stream, _)) => {
|
||||||
let (write_half, read_half) = ws_stream.split();
|
let (write_half, read_half) = ws_stream.split();
|
||||||
|
|
@ -98,6 +102,9 @@ impl OmikronConnection {
|
||||||
let cloned_self = self.clone();
|
let cloned_self = self.clone();
|
||||||
let handle = tokio::spawn(async move {
|
let handle = tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
cloned_self.send_ping().await;
|
cloned_self.send_ping().await;
|
||||||
sleep(Duration::from_secs(1)).await;
|
sleep(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
|
|
@ -139,6 +146,9 @@ impl OmikronConnection {
|
||||||
let sel_arc_out = self.clone();
|
let sel_arc_out = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(msg) = read_half.next().await {
|
while let Some(msg) = read_half.next().await {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let waiting = waiting_out.clone();
|
let waiting = waiting_out.clone();
|
||||||
let writer = writer_out.clone();
|
let writer = writer_out.clone();
|
||||||
let is_connected = is_connected_out.clone();
|
let is_connected = is_connected_out.clone();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::SHUTDOWN;
|
||||||
use crate::auth::auth_connector::unregister_user;
|
use crate::auth::auth_connector::unregister_user;
|
||||||
use crate::communities::community::Community;
|
use crate::communities::community::Community;
|
||||||
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes};
|
||||||
|
|
@ -39,6 +40,14 @@ pub async fn handle(
|
||||||
};
|
};
|
||||||
let (status, content, body_text) = if path_parts.len() >= 3 {
|
let (status, content, body_text) = if path_parts.len() >= 3 {
|
||||||
match path_parts[2] {
|
match path_parts[2] {
|
||||||
|
"shutdown" => {
|
||||||
|
*SHUTDOWN.write().await = true;
|
||||||
|
(
|
||||||
|
StatusCode::OK,
|
||||||
|
"application/json",
|
||||||
|
"{\"type\":\"success\"}".to_string(),
|
||||||
|
)
|
||||||
|
}
|
||||||
"app_state" => (StatusCode::OK, "application/json", {
|
"app_state" => (StatusCode::OK, "application/json", {
|
||||||
let with = headers
|
let with = headers
|
||||||
.get("size")
|
.get("size")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::SHUTDOWN;
|
||||||
use crate::gui::log_panel::log_message;
|
use crate::gui::log_panel::log_message;
|
||||||
use crate::server::api;
|
use crate::server::api;
|
||||||
use crate::server::socket::handle;
|
use crate::server::socket::handle;
|
||||||
|
|
@ -233,6 +234,9 @@ async fn run_http_server(port: u16) -> bool {
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
match listener.accept().await {
|
match listener.accept().await {
|
||||||
std::result::Result::Ok((stream, addr)) => {
|
std::result::Result::Ok((stream, addr)) => {
|
||||||
let service = HttpService { peer_addr: addr };
|
let service = HttpService { peer_addr: addr };
|
||||||
|
|
@ -287,6 +291,9 @@ async fn run_tls_server(port: u16, tls_config: Arc<ServerConfig>) -> bool {
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
match listener.accept().await {
|
match listener.accept().await {
|
||||||
std::result::Result::Ok((stream, addr)) => {
|
std::result::Result::Ok((stream, addr)) => {
|
||||||
let service = HttpService { peer_addr: addr };
|
let service = HttpService { peer_addr: addr };
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::SHUTDOWN;
|
||||||
use crate::communities::{community_connection::CommunityConnection, community_manager};
|
use crate::communities::{community_connection::CommunityConnection, community_manager};
|
||||||
use crate::gui::log_panel::log_message;
|
use crate::gui::log_panel::log_message;
|
||||||
use crate::omikron::omikron_connection::OmikronConnection;
|
use crate::omikron::omikron_connection::OmikronConnection;
|
||||||
|
|
@ -26,6 +27,9 @@ pub fn handle(
|
||||||
let community_conn: Arc<CommunityConnection> =
|
let community_conn: Arc<CommunityConnection> =
|
||||||
Arc::from(CommunityConnection::new(writer, reader, community));
|
Arc::from(CommunityConnection::new(writer, reader, community));
|
||||||
loop {
|
loop {
|
||||||
|
if *SHUTDOWN.read().await {
|
||||||
|
break;
|
||||||
|
}
|
||||||
let msg_result = {
|
let msg_result = {
|
||||||
let mut session_lock = community_conn.receiver.write().await;
|
let mut session_lock = community_conn.receiver.write().await;
|
||||||
session_lock.next().await
|
session_lock.next().await
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue