-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9d16cb
commit 3e3d9c6
Showing
6 changed files
with
441 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.