Skip to content

Commit

Permalink
change: Streamline message type names
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Feb 21, 2025
1 parent 02a6d13 commit 3df8c55
Show file tree
Hide file tree
Showing 90 changed files with 281 additions and 322 deletions.
6 changes: 3 additions & 3 deletions pueue/src/client/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use pueue_lib::{
Request, Response,
client::Client,
format::format_datetime,
network::message::{AddMessage, AddedTaskMessage},
network::message::{AddRequest, AddedTaskResponse},
};

use super::{follow as follow_cmd, group_or_default, handle_response};
Expand Down Expand Up @@ -51,7 +51,7 @@ pub async fn add_task(
}

// Add the message to the daemon.
let message = Request::Add(AddMessage {
let message = Request::Add(AddRequest {
command: command.join(" "),
path,
// Catch the current environment for later injection into the task's process.
Expand All @@ -70,7 +70,7 @@ pub async fn add_task(
let response = client.receive_response().await?;

// Make sure the task has been added, otherwise handle the response and return.
let Response::AddedTask(AddedTaskMessage {
let Response::AddedTask(AddedTaskResponse {
task_id,
enqueue_at,
group_is_paused,
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub async fn clean(
successful_only: bool,
) -> Result<()> {
client
.send_request(CleanMessage {
.send_request(CleanRequest {
successful_only,
group,
})
Expand Down
4 changes: 3 additions & 1 deletion pueue/src/client/commands/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ pub async fn edit(client: &mut Client, style: &OutputStyle, task_ids: Vec<usize>
};

// Send the edited tasks back to the daemon.
client.send_request(Request::Edit(editable_tasks)).await?;
client
.send_request(Request::EditedTasks(editable_tasks))
.await?;

let response = client.receive_response().await?;
handle_response(style, response)?;
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/enqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn enqueue(
delay_until: Option<DateTime<Local>>,
) -> Result<()> {
client
.send_request(EnqueueMessage {
.send_request(EnqueueRequest {
tasks: selection_from_params(all, group, task_ids),
enqueue_at: delay_until,
})
Expand Down
6 changes: 3 additions & 3 deletions pueue/src/client/commands/env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pueue_lib::{client::Client, network::message::EnvMessage};
use pueue_lib::{client::Client, network::message::EnvRequest};

use super::handle_response;
use crate::{
Expand All @@ -13,12 +13,12 @@ pub async fn env(client: &mut Client, style: &OutputStyle, cmd: EnvCommand) -> R
task_id,
key,
value,
} => EnvMessage::Set {
} => EnvRequest::Set {
task_id,
key,
value,
},
EnvCommand::Unset { task_id, key } => EnvMessage::Unset { task_id, key },
EnvCommand::Unset { task_id, key } => EnvRequest::Unset { task_id, key },
};

client.send_request(request).await?;
Expand Down
4 changes: 2 additions & 2 deletions pueue/src/client/commands/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use pueue_lib::{
Response,
client::Client,
log::{get_log_file_handle, get_log_path, seek_to_last_lines},
network::message::StreamRequestMessage,
network::message::StreamRequest,
};
use tokio::time::sleep;

Expand Down Expand Up @@ -53,7 +53,7 @@ pub async fn remote_follow(
) -> Result<()> {
// Request the log stream.
client
.send_request(StreamRequestMessage { task_id, lines })
.send_request(StreamRequest { task_id, lines })
.await?;

// Receive the stream until the connection is closed, breaks or another failure appears.
Expand Down
8 changes: 4 additions & 4 deletions pueue/src/client/commands/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub async fn group(
json: bool,
) -> Result<()> {
let request = match cmd {
Some(GroupCommand::Add { name, parallel }) => GroupMessage::Add {
Some(GroupCommand::Add { name, parallel }) => GroupRequest::Add {
name: name.to_owned(),
parallel_tasks: parallel.to_owned(),
},
Some(GroupCommand::Remove { name }) => GroupMessage::Remove(name.to_owned()),
None => GroupMessage::List,
Some(GroupCommand::Remove { name }) => GroupRequest::Remove(name.to_owned()),
None => GroupRequest::List,
};

client.send_request(request).await?;
Expand All @@ -37,7 +37,7 @@ pub async fn group(

/// Print some info about the daemon's current groups.
/// This is used when calling `pueue group`.
pub fn format_groups(message: GroupResponseMessage, style: &OutputStyle, json: bool) -> String {
pub fn format_groups(message: GroupResponse, style: &OutputStyle, json: bool) -> String {
if json {
return serde_json::to_string(&message.groups).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub async fn kill(
}

client
.send_request(KillMessage {
.send_request(KillRequest {
tasks: selection_from_params(all, group, task_ids),
signal,
})
Expand Down
12 changes: 7 additions & 5 deletions pueue/src/client/commands/log/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{

use pueue_lib::{
log::{get_log_file_handle, read_last_lines},
network::message::TaskLogMessage,
network::message::TaskLogResponse,
settings::Settings,
task::Task,
};
Expand All @@ -19,16 +19,18 @@ pub struct TaskLog {
pub output: String,
}

/// Print some log output in JSON serialized form.
///
/// If the log isn't read from the disk but rather received from the daemon, we have to
/// convert the received [TaskLogResponse] into a proper JSON serializable format.
/// Output in [TaskLogResponse], is usually compressed, so we need to decompress it first.
pub fn print_log_json(
task_log_messages: BTreeMap<usize, TaskLogMessage>,
task_log_messages: BTreeMap<usize, TaskLogResponse>,
settings: &Settings,
lines: Option<usize>,
) {
let mut tasks: BTreeMap<usize, Task> = BTreeMap::new();
let mut task_log: BTreeMap<usize, String> = BTreeMap::new();
// Convert the TaskLogMessage into a proper JSON serializable format.
// Output in TaskLogMessages, if it exists, is compressed.
// We need to decompress and convert to normal strings.
for (id, message) in task_log_messages {
tasks.insert(id, message.task);

Expand Down
6 changes: 3 additions & 3 deletions pueue/src/client/commands/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use comfy_table::{Attribute as ComfyAttribute, Cell, CellAlignment, Table};
use crossterm::style::Color;
use pueue_lib::{
client::Client,
network::message::{TaskLogMessage, TaskSelection, *},
network::message::{TaskLogResponse, TaskSelection, *},
settings::Settings,
task::{Task, TaskResult, TaskStatus},
};
Expand Down Expand Up @@ -35,7 +35,7 @@ pub async fn print_logs(
let selection = selection_from_params(all, group.clone(), task_ids.clone());

client
.send_request(LogRequestMessage {
.send_request(LogRequest {
tasks: selection.clone(),
send_logs: !client.settings.client.read_local_logs,
lines,
Expand Down Expand Up @@ -119,7 +119,7 @@ fn determine_log_line_amount(full: bool, lines: &Option<usize>) -> Option<usize>
/// `None` implicates that everything should be printed.
/// This is only important, if we read local lines.
fn print_log(
message: &TaskLogMessage,
message: &TaskLogResponse,
style: &OutputStyle,
settings: &Settings,
lines: Option<usize>,
Expand Down
6 changes: 2 additions & 4 deletions pueue/src/client/commands/log/remote.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use std::io;

use crossterm::style::{Attribute, Color};
use pueue_lib::network::message::TaskLogMessage;
use pueue_lib::network::message::TaskLogResponse;
use snap::read::FrameDecoder;

use super::OutputStyle;
use crate::internal_prelude::*;

/// Prints log output received from the daemon.
/// We can safely call .unwrap() on output in here, since this
/// branch is always called after ensuring that it is `Some`.
pub fn print_remote_log(task_log: &TaskLogMessage, style: &OutputStyle, lines: Option<usize>) {
pub fn print_remote_log(task_log: &TaskLogResponse, style: &OutputStyle, lines: Option<usize>) {
if let Some(bytes) = task_log.output.as_ref() {
if !bytes.is_empty() {
// Add a hint if we should limit the output to X lines **and** there are actually more
Expand Down
4 changes: 2 additions & 2 deletions pueue/src/client/commands/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub async fn parallel(
let request: Request = match parallel_tasks {
Some(parallel_tasks) => {
let group = group_or_default(&group);
ParallelMessage {
ParallelRequest {
parallel_tasks,
group,
}
.into()
}
None => GroupMessage::List.into(),
None => GroupRequest::List.into(),
};

client.send_request(request).await?;
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub async fn pause(
wait: bool,
) -> Result<()> {
client
.send_request(PauseMessage {
.send_request(PauseRequest {
tasks: selection_from_params(all, group, task_ids),
wait,
})
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn reset(
ResetTarget::Groups(groups.clone())
};

client.send_request(ResetMessage { target }).await?;
client.send_request(ResetRequest { target }).await?;
let response = client.receive_response().await?;

handle_response(style, response)
Expand Down
8 changes: 4 additions & 4 deletions pueue/src/client/commands/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
internal_prelude::*,
};

/// When restarting tasks, the remote state is queried and a [AddMessage]
/// When restarting tasks, the remote state is queried and a [AddRequest]
/// is create from the existing task in the state.
///
/// This is done on the client-side, so we can easily edit the task before restarting it.
Expand Down Expand Up @@ -89,7 +89,7 @@ pub async fn restart(

// Build a RestartMessage, if the tasks should be replaced instead of creating a copy of the
// original task. This is only important, if replace is `True`.
let mut restart_message = RestartMessage {
let mut restart_message = RestartRequest {
tasks: Vec::new(),
stashed,
start_immediately,
Expand Down Expand Up @@ -135,9 +135,9 @@ pub async fn restart(
}

// In case we don't do in-place restarts, we have to add a new task.
// Create a AddMessage to send the task to the daemon from the updated info and the old
// Create an request to send the task to the daemon from the updated info and the old
// task.
let add_task_message = AddMessage {
let add_task_message = AddRequest {
command: task.command,
path: task.path,
envs: task.envs.clone(),
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub async fn send(
task_id: usize,
input: String,
) -> Result<()> {
client.send_request(SendMessage { task_id, input }).await?;
client.send_request(SendRequest { task_id, input }).await?;

let response = client.receive_response().await?;

Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{client::style::OutputStyle, internal_prelude::*};

/// Initiate a daemon shutdown
pub async fn shutdown(client: &mut Client, style: &OutputStyle) -> Result<()> {
client.send_request(Shutdown::Graceful).await?;
client.send_request(ShutdownRequest::Graceful).await?;

let response = client.receive_response().await?;

Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub async fn start(
all: bool,
) -> Result<()> {
client
.send_request(StartMessage {
.send_request(StartRequest {
tasks: selection_from_params(all, group, task_ids),
})
.await?;
Expand Down
4 changes: 2 additions & 2 deletions pueue/src/client/commands/stash.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use chrono::{DateTime, Local};
use pueue_lib::{client::Client, network::message::StashMessage};
use pueue_lib::{client::Client, network::message::StashRequest};

use super::{handle_response, selection_from_params};
use crate::{client::style::OutputStyle, internal_prelude::*};
Expand All @@ -15,7 +15,7 @@ pub async fn stash(
) -> Result<()> {
let selection = selection_from_params(all, group, task_ids);
client
.send_request(StashMessage {
.send_request(StashRequest {
tasks: selection,
enqueue_at: delay_until,
})
Expand Down
2 changes: 1 addition & 1 deletion pueue/src/client/commands/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub async fn switch(
task_id_2: usize,
) -> Result<()> {
client
.send_request(SwitchMessage {
.send_request(SwitchRequest {
task_id_1,
task_id_2,
})
Expand Down
2 changes: 0 additions & 2 deletions pueue/src/client/commands/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ pub async fn wait(
return Ok(());
}

// Get current time for log output

// Iterate over all matching tasks
for task in tasks.iter() {
// Get the previous status of the task.
Expand Down
3 changes: 1 addition & 2 deletions pueue/src/daemon/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::collections::HashMap;
use chrono::{DateTime, Local};
use handlebars::{Handlebars, RenderError};
use pueue_lib::{
Settings, Task, TaskResult, TaskStatus,
log::{get_log_path, read_last_log_file_lines},
settings::Settings,
task::{Task, TaskResult, TaskStatus},
};

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions pueue/src/daemon/internal_state/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use flate2::Compression;
use pueue_lib::{
Group, GroupStatus, Settings, State, TaskResult,
error::Error,
network::message::request::Shutdown,
network::message::request::ShutdownRequest,
state::{FilteredTasks, PUEUE_DEFAULT_GROUP},
task::{Task, TaskStatus},
};
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct InternalState {
/// Depending on the shutdown type, we're exiting with different exitcodes.
/// This is runtime state and won't be serialised to disk.
#[serde(default, skip)]
pub shutdown: Option<Shutdown>,
pub shutdown: Option<ShutdownRequest>,

/// Pueue's subprocess and worker pool representation.
/// Take a look at [Children] for more info.
Expand Down
6 changes: 3 additions & 3 deletions pueue/src/daemon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::{

use process_handler::initiate_shutdown;
use pueue_lib::{
Settings,
error::Error,
network::{
certificate::create_certificates, message::Shutdown, protocol::socket_cleanup,
certificate::create_certificates, message::ShutdownRequest, protocol::socket_cleanup,
secret::init_shared_secret,
},
settings::Settings,
};
use tokio::try_join;

Expand Down Expand Up @@ -150,7 +150,7 @@ fn setup_signal_panic_handling(settings: &Settings, state: SharedState) -> Resul
// The actual program exit will be done via the TaskHandler.
ctrlc::set_handler(move || {
let mut state = state_clone.lock().unwrap();
initiate_shutdown(&settings_clone, &mut state, Shutdown::Graceful);
initiate_shutdown(&settings_clone, &mut state, ShutdownRequest::Graceful);
})?;

// Try to do some final cleanup, even if we panic.
Expand Down
Loading

0 comments on commit 3df8c55

Please sign in to comment.