Skip to content

Commit

Permalink
Move progress tracker completion from StatesDiscoverCmd to `CmdExec…
Browse files Browse the repository at this point in the history
…ution`.
  • Loading branch information
azriel91 committed Sep 17, 2023
1 parent 5117580 commit 69ed11d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
35 changes: 33 additions & 2 deletions crate/cmd_rt/src/cmd_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ use crate::{CmdBlockError, CmdBlockRtBox};
cfg_if::cfg_if! {
if #[cfg(feature = "output_progress")] {
use peace_cmd::scopes::SingleProfileSingleFlowViewAndOutput;
use peace_cfg::progress::ProgressUpdateAndId;
use peace_cfg::progress::{
ProgressComplete,
ProgressStatus,
ProgressUpdateAndId,
};
use peace_rt_model::CmdProgressTracker;
use tokio::sync::mpsc::{self, Sender};

use crate::Progress;
Expand Down Expand Up @@ -177,11 +182,37 @@ where
let (cmd_outcome, ()) = futures::join!(cmd_outcome_task, progress_render_task);

#[cfg(feature = "output_progress")]
output.progress_end(cmd_progress_tracker).await;
{
if let Ok(cmd_outcome) = cmd_outcome.as_ref() {
Self::progress_bar_mark_complete_on_ok(cmd_progress_tracker, cmd_outcome);
}
output.progress_end(cmd_progress_tracker).await;
}

cmd_outcome
}

#[cfg(feature = "output_progress")]
fn progress_bar_mark_complete_on_ok<T>(
cmd_progress_tracker: &mut CmdProgressTracker,
cmd_outcome: &CmdOutcome<T, E>,
) {
cmd_progress_tracker
.progress_trackers_mut()
.iter_mut()
.filter_map(|(item_id, progress_tracker)| {
if cmd_outcome.errors.contains_key(item_id) {
None
} else {
Some(progress_tracker)
}
})
.for_each(|progress_tracker| {
progress_tracker
.set_progress_status(ProgressStatus::Complete(ProgressComplete::Success))
})
}

// pub fn exec_bg -> CmdExecId
}

Expand Down
34 changes: 0 additions & 34 deletions crate/rt/src/cmds/states_discover_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use peace_rt_model::{

use crate::cmd_blocks::StatesDiscoverCmdBlock;

#[cfg(feature = "output_progress")]
use peace_cfg::progress::{ProgressComplete, ProgressStatus};

pub struct StatesDiscoverCmd<E, O, PKeys>(PhantomData<(E, O, PKeys)>);

impl<E, O, PKeys> Debug for StatesDiscoverCmd<E, O, PKeys> {
Expand Down Expand Up @@ -99,9 +96,6 @@ where
Self::serialize_current(item_graph, resources, states_current).await?;
}

#[cfg(feature = "output_progress")]
Self::progress_bar_mark_complete_on_ok(cmd_ctx, &cmd_outcome);

Ok(cmd_outcome)
}

Expand Down Expand Up @@ -170,9 +164,6 @@ where
Self::serialize_goal(item_graph, resources, states_goal).await?;
}

#[cfg(feature = "output_progress")]
Self::progress_bar_mark_complete_on_ok(cmd_ctx, &cmd_outcome);

Ok(cmd_outcome)
}

Expand Down Expand Up @@ -272,9 +263,6 @@ where
Self::serialize_goal(item_graph, resources, states_goal).await?;
}

#[cfg(feature = "output_progress")]
Self::progress_bar_mark_complete_on_ok(cmd_ctx, &cmd_outcome);

Ok(cmd_outcome)
}

Expand Down Expand Up @@ -321,28 +309,6 @@ where

Ok(())
}

#[cfg(feature = "output_progress")]
fn progress_bar_mark_complete_on_ok<T>(
cmd_ctx: &mut CmdCtx<SingleProfileSingleFlow<'_, E, O, PKeys, SetUp>>,
cmd_outcome: &CmdOutcome<T, E>,
) {
cmd_ctx
.cmd_progress_tracker_mut()
.progress_trackers_mut()
.iter_mut()
.filter_map(|(item_id, progress_tracker)| {
if cmd_outcome.errors.contains_key(item_id) {
None
} else {
Some(progress_tracker)
}
})
.for_each(|progress_tracker| {
progress_tracker
.set_progress_status(ProgressStatus::Complete(ProgressComplete::Success))
})
}
}

impl<E, O, PKeys> Default for StatesDiscoverCmd<E, O, PKeys> {
Expand Down

0 comments on commit 69ed11d

Please sign in to comment.