Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove api pinger #124

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async fn set_usage_msg(report_service: &Endpoint, activity_id: &str, current_usa
})
.await
{
Ok(Ok(())) => log::debug!("Successfully sent activity usage message"),
Ok(Ok(())) => log::trace!("Successfully sent activity usage message"),
Ok(Err(rpc_message_error)) => {
log::error!("rpcMessageError : {:?}", rpc_message_error)
}
Expand Down
34 changes: 1 addition & 33 deletions src/process/automatic/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::process::OutputLines;

use super::*;

use reqwest::Client;
use std::sync::Arc;
use tokio::sync::oneshot::{self};
use tokio::task::JoinHandle;
Expand All @@ -11,8 +10,6 @@ use tokio_stream::StreamExt;
pub(super) struct OutputMonitor {
#[allow(dead_code)]
output_task: Arc<JoinHandle<()>>,
#[allow(dead_code)]
pinger_task: Arc<JoinHandle<()>>,
}

impl OutputMonitor {
Expand All @@ -23,17 +20,12 @@ impl OutputMonitor {
config: config.clone(),
};
let output_task = Arc::new(spawn_output_monitoring(lines, output_handler));
// Repetitive calling Automatic API triggers flushing Automatic process `stdout`.
let pinger_task = Arc::new(spawn_api_pinger(config.clone()));

on_startup_rx
.await
.context("Automatic failed on startup")??;

Ok(Self {
output_task,
pinger_task,
})
Ok(Self { output_task })
}
}

Expand All @@ -53,30 +45,6 @@ fn spawn_output_monitoring(
})
}

/// Repetitive calling Automatic API triggers flushing process `stdout`.
/// It is required to log it, to monitor Automatic startup, and its shutdown.
/// When Automatic is started from console its output gets flushed.
/// Description and solution idea for faced issue https://stackoverflow.com/a/39528785/2608409
fn spawn_api_pinger(config: Config) -> JoinHandle<()> {
log::debug!("Starting API pinger");
let url = format!("http://{}:{}", config.api_host, config.api_port);
let client = Client::new().get(url);
tokio::spawn(async move {
loop {
let Some(client) = client.try_clone() else {
log::error!("Unable ping API");
break;
};
log::trace!("Pinging API");
match client.send().await {
Ok(response) => log::trace!("Ping respone: {response:?}"),
Err(err) => log::warn!("Ping failure: {err:?}"),
};
tokio::time::sleep(config.api_ping_delay).await;
}
})
}

enum OutputHandler {
LookingForStartup {
//TODO create a custom error type?
Expand Down