truncate output
This commit is contained in:
+7
-7
@@ -88,7 +88,7 @@ async fn process_messages(
|
|||||||
return Err("Server did not respond to ping".into());
|
return Err("Server did not respond to ping".into());
|
||||||
}
|
}
|
||||||
next_message = stream.next() => {
|
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?
|
.await?
|
||||||
{
|
{
|
||||||
awaiting_pong = false;
|
awaiting_pong = false;
|
||||||
@@ -101,14 +101,14 @@ async fn process_messages(
|
|||||||
async fn handle_stream_message(
|
async fn handle_stream_message(
|
||||||
message: Option<Result<Message, tokio_tungstenite::tungstenite::Error>>,
|
message: Option<Result<Message, tokio_tungstenite::tungstenite::Error>>,
|
||||||
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
|
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
|
||||||
max_output_bytes: u64,
|
max_result_bytes: u64,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
match message {
|
match message {
|
||||||
Some(Ok(Message::Text(text))) => {
|
Some(Ok(Message::Text(text))) => {
|
||||||
handle_server_message(
|
handle_server_message(
|
||||||
serde_json::from_str(&text).map_err(|error| error.to_string())?,
|
serde_json::from_str(&text).map_err(|error| error.to_string())?,
|
||||||
outgoing_tx,
|
outgoing_tx,
|
||||||
max_output_bytes,
|
max_result_bytes,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(false)
|
Ok(false)
|
||||||
@@ -130,11 +130,11 @@ async fn handle_stream_message(
|
|||||||
async fn handle_server_message(
|
async fn handle_server_message(
|
||||||
message: ServerMsg,
|
message: ServerMsg,
|
||||||
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
|
outgoing_tx: &mpsc::Sender<OutgoingMessage>,
|
||||||
max_output_bytes: u64,
|
max_result_bytes: u64,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match message {
|
match message {
|
||||||
ServerMsg::Exec { exec_id, command } => {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
ServerMsg::AuthError { reason } => Err(reason),
|
ServerMsg::AuthError { reason } => Err(reason),
|
||||||
@@ -146,11 +146,11 @@ fn spawn_command_task(
|
|||||||
exec_id: String,
|
exec_id: String,
|
||||||
command: String,
|
command: String,
|
||||||
outgoing_tx: mpsc::Sender<OutgoingMessage>,
|
outgoing_tx: mpsc::Sender<OutgoingMessage>,
|
||||||
max_output_bytes: u64,
|
max_result_bytes: u64,
|
||||||
) {
|
) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
info!("Executing [{exec_id}]: {command}");
|
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 {
|
let result = ClientMsg::ExecResult {
|
||||||
exec_id,
|
exec_id,
|
||||||
exit_code,
|
exit_code,
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ pub struct Config {
|
|||||||
pub token: String,
|
pub token: String,
|
||||||
pub device_id: String,
|
pub device_id: String,
|
||||||
pub base_url: String,
|
pub base_url: String,
|
||||||
pub max_output_bytes: u64,
|
pub max_result_bytes: u64,
|
||||||
pub writer_channel_capacity: usize,
|
pub writer_channel_capacity: usize,
|
||||||
pub ping_interval: Duration,
|
pub ping_interval: Duration,
|
||||||
pub ping_timeout: Duration,
|
pub ping_timeout: Duration,
|
||||||
@@ -13,7 +13,7 @@ pub struct Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
const DEFAULT_BASE_URL: &str = "ws://127.0.0.1:8000";
|
const DEFAULT_BASE_URL: &str = "ws://127.0.0.1:8000";
|
||||||
const DEFAULT_DEVICE_ID: &str = "device";
|
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_WRITER_CHANNEL_CAPACITY: usize = 32;
|
||||||
const DEFAULT_PING_INTERVAL_SECS: u64 = 30;
|
const DEFAULT_PING_INTERVAL_SECS: u64 = 30;
|
||||||
const DEFAULT_PING_TIMEOUT_SECS: u64 = 10;
|
const DEFAULT_PING_TIMEOUT_SECS: u64 = 10;
|
||||||
@@ -31,7 +31,7 @@ impl Config {
|
|||||||
token,
|
token,
|
||||||
device_id,
|
device_id,
|
||||||
base_url,
|
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: parse_env(
|
||||||
"WRITER_CHANNEL_CAPACITY",
|
"WRITER_CHANNEL_CAPACITY",
|
||||||
Self::DEFAULT_WRITER_CHANNEL_CAPACITY,
|
Self::DEFAULT_WRITER_CHANNEL_CAPACITY,
|
||||||
|
|||||||
Reference in New Issue
Block a user