truncate output

This commit is contained in:
2026-05-22 08:55:14 +02:00
parent 755c65f1f1
commit deec183ff5
2 changed files with 10 additions and 10 deletions
+7 -7
View File
@@ -88,7 +88,7 @@ async fn process_messages(
return Err("Server did not respond to ping".into());
}
next_message = stream.next() => {
if handle_stream_message(next_message, &outgoing_tx, config.max_output_bytes)
if handle_stream_message(next_message, &outgoing_tx, config.max_result_bytes)
.await?
{
awaiting_pong = false;
@@ -101,14 +101,14 @@ async fn process_messages(
async fn handle_stream_message(
message: Option<Result<Message, tokio_tungstenite::tungstenite::Error>>,
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
max_output_bytes: u64,
max_result_bytes: u64,
) -> Result<bool, String> {
match message {
Some(Ok(Message::Text(text))) => {
handle_server_message(
serde_json::from_str(&text).map_err(|error| error.to_string())?,
outgoing_tx,
max_output_bytes,
max_result_bytes,
)
.await?;
Ok(false)
@@ -130,11 +130,11 @@ async fn handle_stream_message(
async fn handle_server_message(
message: ServerMsg,
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
max_output_bytes: u64,
max_result_bytes: u64,
) -> Result<(), String> {
match message {
ServerMsg::Exec { exec_id, command } => {
spawn_command_task(exec_id, command, outgoing_tx.clone(), max_output_bytes);
spawn_command_task(exec_id, command, outgoing_tx.clone(), max_result_bytes);
Ok(())
}
ServerMsg::AuthError { reason } => Err(reason),
@@ -146,11 +146,11 @@ fn spawn_command_task(
exec_id: String,
command: String,
outgoing_tx: mpsc::Sender<OutgoingMessage>,
max_output_bytes: u64,
max_result_bytes: u64,
) {
tokio::spawn(async move {
info!("Executing [{exec_id}]: {command}");
let (exit_code, stdout, stderr) = command::execute(&command, max_output_bytes).await;
let (exit_code, stdout, stderr) = command::execute(&command, max_result_bytes).await;
let result = ClientMsg::ExecResult {
exec_id,
exit_code,
+3 -3
View File
@@ -4,7 +4,7 @@ pub struct Config {
pub token: String,
pub device_id: String,
pub base_url: String,
pub max_output_bytes: u64,
pub max_result_bytes: u64,
pub writer_channel_capacity: usize,
pub ping_interval: Duration,
pub ping_timeout: Duration,
@@ -13,7 +13,7 @@ pub struct Config {
impl Config {
const DEFAULT_BASE_URL: &str = "ws://127.0.0.1:8000";
const DEFAULT_DEVICE_ID: &str = "device";
const DEFAULT_MAX_OUTPUT_BYTES: u64 = 10 * 1024 * 1024;
const DEFAULT_MAX_RESULT_BYTES: u64 = 10 * 1024 * 1024;
const DEFAULT_WRITER_CHANNEL_CAPACITY: usize = 32;
const DEFAULT_PING_INTERVAL_SECS: u64 = 30;
const DEFAULT_PING_TIMEOUT_SECS: u64 = 10;
@@ -31,7 +31,7 @@ impl Config {
token,
device_id,
base_url,
max_output_bytes: parse_env("MAX_OUTPUT_BYTES", Self::DEFAULT_MAX_OUTPUT_BYTES),
max_result_bytes: parse_env("MAX_RESULT_BYTES", Self::DEFAULT_MAX_RESULT_BYTES),
writer_channel_capacity: parse_env(
"WRITER_CHANNEL_CAPACITY",
Self::DEFAULT_WRITER_CHANNEL_CAPACITY,