Skip to content

Commit

Permalink
Merge pull request #124 from golemfactory/remove-automatic-pinger
Browse files Browse the repository at this point in the history
Remove api pinger
  • Loading branch information
nieznanysprawiciel authored Aug 1, 2024
2 parents a8b4d45 + 577d298 commit f2fa46b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
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

0 comments on commit f2fa46b

Please sign in to comment.