Skip to content

Commit

Permalink
Simplify the CLI of dashboard
Browse files Browse the repository at this point in the history
Stream replays old events by default, so the combination of reading a journal file + stream is not needed.
  • Loading branch information
Kobzol committed Jan 3, 2025
1 parent 233e87f commit ab01664
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
8 changes: 4 additions & 4 deletions crates/hyperqueue/src/bin/hq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,20 +299,20 @@ async fn command_dashboard_start(
) -> anyhow::Result<()> {
use hyperqueue::common::cli::DashboardCommand;
use hyperqueue::dashboard::start_ui_loop;
use hyperqueue::server::event::log::JournalReader;
use hyperqueue::server::event::journal::JournalReader;
use hyperqueue::server::event::Event;

match opts.subcmd.unwrap_or_default() {
DashboardCommand::Replay { journal, stream } => {
DashboardCommand::Replay { journal } => {
println!("Loading journal {}", journal.display());
let mut journal = JournalReader::open(&journal)?;
let events: Vec<Event> = journal.collect::<Result<_, _>>()?;
println!("Loaded {} events", events.len());

start_ui_loop(gsettings, events, stream).await?;
start_ui_loop(gsettings, Some(events)).await?;
}
DashboardCommand::Stream => {
start_ui_loop(gsettings, vec![], true).await?;
start_ui_loop(gsettings, None).await?;
}
}

Expand Down
5 changes: 2 additions & 3 deletions crates/hyperqueue/src/common/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,14 @@ pub struct DashboardOpts {
#[derive(Parser, Default)]
pub enum DashboardCommand {
/// Stream events from a server.
/// Note that this will replay all events from the currently active
/// journal file before new events will be streamed.
#[default]
Stream,
/// Replay events from a recorded journal file.
Replay {
/// Path to a journal file created via `hq server start --journal=<path>`.
journal: PathBuf,
/// Also stream new events from a server after replaying events from the journal.
#[clap(long)]
stream: bool,
},
}

Expand Down
23 changes: 15 additions & 8 deletions crates/hyperqueue/src/dashboard/ui_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures::StreamExt;
use std::future::Future;
use std::ops::ControlFlow;
use std::pin::Pin;
use std::time::SystemTime;
use tokio::time::Duration;

use crate::client::globalsettings::GlobalSettings;
Expand All @@ -18,18 +19,24 @@ use crate::server::event::Event;
/// Starts the dashboard UI with a keyboard listener and tick provider
pub async fn start_ui_loop(
gsettings: &GlobalSettings,
events: Vec<Event>,
stream: bool,
events: Option<Vec<Event>>,
) -> anyhow::Result<()> {
let time_mode = if stream || events.is_empty() {
TimeMode::Live(DEFAULT_LIVE_DURATION)
} else {
let end = events.last().unwrap().time.into();
TimeMode::Fixed(TimeRange::new(end - Duration::from_secs(60 * 5), end))
let stream = events.is_none();
let time_mode = match &events {
Some(events) => {
let end = match events.last() {
Some(event) => event.time.into(),
None => SystemTime::now(),
};
TimeMode::Fixed(TimeRange::new(end - Duration::from_secs(60 * 5), end))
}
None => TimeMode::Live(DEFAULT_LIVE_DURATION),
};

let mut dashboard_data = DashboardData::new(time_mode, stream);
dashboard_data.push_new_events(events);
if let Some(events) = events {
dashboard_data.push_new_events(events);
}

let mut root_screen = RootScreen::default();

Expand Down

0 comments on commit ab01664

Please sign in to comment.