Skip to content

Commit

Permalink
nice progress
Browse files Browse the repository at this point in the history
  • Loading branch information
j4cobgarby committed May 20, 2024
1 parent e9d16cb commit 3e3d9c6
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 18 deletions.
144 changes: 144 additions & 0 deletions rsman/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rsman/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ name = "resman"
path = "src/client/main.rs"

[dependencies]
nix = { version = "0.28.0", features = ["signal"] }
serde = "1.0.201"
clap = { version = "4.5.4", features = ["derive"] }
nix = { version = "0.28.0", features = ["signal", "user"] }
serde = { version = "1.0.201", features = ["derive"] }
serde_json = "1.0.117"
tokio = { version = "1", features = ["full"] }
50 changes: 50 additions & 0 deletions rsman/lib/resman_common.rs
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
use serde::{Deserialize, Serialize};

pub const SOCKET_NAME: &str = "/tmp/resman_socket";

#[derive(Debug, Serialize, Deserialize)]
pub enum IPCMessage {
QueueReq(QueueRequest),
SkipReq(SkipRequest),
StatReq(StatusRequest),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct QueueRequest {
pub pid: i32,
pub uid: u32,
pub msg: String,
pub cmd: String, // it's not run by the server, but sent out of interest
}

#[derive(Debug, Serialize, Deserialize)]
pub struct QueueResponse {
pub success: bool,
pub place_in_queue: i32,
pub job_id: i32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SkipRequest {
pub job_id: i32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SkipResponse {
pub success: bool,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct StatusRequest {}

#[derive(Debug, Serialize, Deserialize)]
pub struct StatusResponse {
pub jobs: Vec<JobStatus>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct JobStatus {
pub job_id: i32,
pub uid: u32,
pub msg: String,
pub elapsed_seconds: i32,
}
85 changes: 82 additions & 3 deletions rsman/src/client/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,84 @@
use resman_common::test;
use clap::{Parser, Subcommand};
use resman_common::*;
use std::io;
use tokio::net::UnixStream;

pub fn main() {
test();
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[command(subcommand)]
subcommand: Subcommands,
}

#[derive(Subcommand, Debug)]
enum Subcommands {
#[command(aliases = &["c", "ch", "chk"], about = "Get reservation status.")]
Check {
#[arg(short, long, help = "Confirm that user has read notice.")]
interactive: bool,

#[arg(short, long, help = "Silence output; only set exit status.")]
silent: bool,
},

#[command(aliases = &["x", "e", "ex", "exe"], about = "Queue a command.")]
Exec {
#[arg(short, long, help = "Short message to show to others.")]
msg: Option<String>,

#[arg(trailing_var_arg = true, help = "The command to queue.")]
args: Vec<String>,
},

#[command(aliases = &["s", "sk"], about = "Skip the current job.")]
Skip {
#[arg(short, long, help = "Skip even other users' jobs.")]
force: bool,
},
}

pub fn main() -> io::Result<()> {
let args = Args::parse();

// let stream = UnixStream::connect(SOCKET_NAME);

match &args.subcommand {
Subcommands::Exec { msg, args } => {
println!("Executing command: {:?}", args);

let req: QueueRequest = QueueRequest {
pid: 1337,
uid: 2,
msg: match msg {
Some(msg) => msg.to_owned(),
None => String::from(""),
},
cmd: args.join(" "),
};

let req = IPCMessage::QueueReq(req);
let req = serde_json::to_string(&req).unwrap();

println!("Serialised = {}", req);

let stream = UnixStream::connect(SOCKET_NAME);
}

Subcommands::Check {
interactive,
silent,
} => {
println!("Server is reserved?: ");

let req: StatusRequest = StatusRequest {};
}

Subcommands::Skip { force } => {
println!("Skipping job...");

let req: SkipRequest = SkipRequest { job_id: 10 };
}
}

Ok(())
}
Loading

0 comments on commit 3e3d9c6

Please sign in to comment.