Skip to content

Commit 9f96da2

Browse files
committed
feat(enterprise): implement job scheduler commands (#162)
- Add Get command to retrieve job scheduler configuration - Add Update command to modify job scheduler settings - Support stdin input with '-' flag for JSON data - Successfully tested against Docker compose environment
1 parent 8b51189 commit 9f96da2

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed

crates/redisctl/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,10 @@ pub enum EnterpriseCommands {
995995
#[command(subcommand)]
996996
Crdb(EnterpriseCrdbCommands),
997997

998+
/// Job scheduler operations
999+
#[command(subcommand, name = "job-scheduler")]
1000+
JobScheduler(crate::commands::enterprise::job_scheduler::JobSchedulerCommands),
1001+
9981002
/// Log operations
9991003
#[command(subcommand)]
10001004
Logs(crate::commands::enterprise::logs::LogsCommands),
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use anyhow::Context;
2+
use clap::Subcommand;
3+
4+
use crate::cli::OutputFormat;
5+
use crate::connection::ConnectionManager;
6+
use crate::error::Result as CliResult;
7+
8+
#[derive(Debug, Clone, Subcommand)]
9+
pub enum JobSchedulerCommands {
10+
/// Get job scheduler configuration/settings
11+
Get,
12+
13+
/// Update job scheduler settings
14+
Update {
15+
/// JSON data for configuration update (use @filename or - for stdin)
16+
#[arg(short, long)]
17+
data: String,
18+
},
19+
}
20+
21+
impl JobSchedulerCommands {
22+
#[allow(dead_code)]
23+
pub async fn execute(
24+
&self,
25+
conn_mgr: &ConnectionManager,
26+
profile_name: Option<&str>,
27+
output_format: OutputFormat,
28+
query: Option<&str>,
29+
) -> CliResult<()> {
30+
let client = conn_mgr.create_enterprise_client(profile_name).await?;
31+
32+
match self {
33+
JobSchedulerCommands::Get => {
34+
// Get job scheduler configuration/settings
35+
let response: serde_json::Value = client
36+
.get("/v1/job_scheduler")
37+
.await
38+
.context("Failed to get job scheduler settings")?;
39+
40+
let output_data = if let Some(q) = query {
41+
super::utils::apply_jmespath(&response, q)?
42+
} else {
43+
response
44+
};
45+
super::utils::print_formatted_output(output_data, output_format)?;
46+
}
47+
48+
JobSchedulerCommands::Update { data } => {
49+
let json_data = super::utils::read_json_data(data)?;
50+
51+
let response: serde_json::Value = client
52+
.put("/v1/job_scheduler", &json_data)
53+
.await
54+
.context("Failed to update job scheduler settings")?;
55+
56+
let output_data = if let Some(q) = query {
57+
super::utils::apply_jmespath(&response, q)?
58+
} else {
59+
response
60+
};
61+
super::utils::print_formatted_output(output_data, output_format)?;
62+
}
63+
}
64+
65+
Ok(())
66+
}
67+
}
68+
69+
#[allow(dead_code)]
70+
pub async fn handle_job_scheduler_command(
71+
conn_mgr: &ConnectionManager,
72+
profile_name: Option<&str>,
73+
job_scheduler_cmd: JobSchedulerCommands,
74+
output_format: OutputFormat,
75+
query: Option<&str>,
76+
) -> CliResult<()> {
77+
job_scheduler_cmd
78+
.execute(conn_mgr, profile_name, output_format, query)
79+
.await
80+
}

crates/redisctl/src/commands/enterprise/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod crdb;
66
pub mod crdb_impl;
77
pub mod database;
88
pub mod database_impl;
9+
pub mod job_scheduler;
910
pub mod logs;
1011
pub mod logs_impl;
1112
pub mod module;

crates/redisctl/src/commands/enterprise/utils.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,22 @@ pub fn confirm_action(message: &str) -> CliResult<bool> {
9292
}
9393
}
9494

95-
/// Read JSON data from string or file
95+
/// Read JSON data from string, file, or stdin
9696
pub fn read_json_data(data: &str) -> CliResult<Value> {
97-
let json_str = if let Some(file_path) = data.strip_prefix('@') {
97+
let json_str = if data == "-" {
98+
// Read from stdin
99+
use std::io::Read;
100+
let mut buffer = String::new();
101+
std::io::stdin()
102+
.read_to_string(&mut buffer)
103+
.map_err(|e| anyhow::anyhow!("Failed to read from stdin: {}", e))?;
104+
buffer
105+
} else if let Some(file_path) = data.strip_prefix('@') {
106+
// Read from file
98107
std::fs::read_to_string(file_path)
99108
.map_err(|e| anyhow::anyhow!("Failed to read file {}: {}", file_path, e))?
100109
} else {
110+
// Direct JSON string
101111
data.to_string()
102112
};
103113

crates/redisctl/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ async fn execute_enterprise_command(
244244
)
245245
.await
246246
}
247+
JobScheduler(job_scheduler_cmd) => {
248+
commands::enterprise::job_scheduler::handle_job_scheduler_command(
249+
conn_mgr,
250+
profile,
251+
job_scheduler_cmd.clone(),
252+
output,
253+
query,
254+
)
255+
.await
256+
}
247257
Logs(logs_cmd) => {
248258
commands::enterprise::logs_impl::handle_logs_commands(
249259
conn_mgr, profile, logs_cmd, output, query,

0 commit comments

Comments
 (0)