-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
progress: send IPC notifications from Sapling
Summary: After this diff, all commands should send progress bars to ISL (or whichever other process is communicating through NodeIPC). This feature will be gated through the `progress.ipc-report` config. Sending progress bars is done under the same loop that renders progress bars and updates the runlog. Sending messages through NodeIPC shouldn't slow down anything else, as there is little information to be updated. Because nothing is slowed down, we don't need another thread to independently send messages through NodeIPC. Notice that we don't put the logic for sending progress bars under the `progress::render` crate. That crate is very tightly couple with `wezterm` features, so it wouldn't make much sense to put it there. Reviewed By: muirdm Differential Revision: D65769370 fbshipit-source-id: d547a6a546d18713737983d40ee53129665ae018
- Loading branch information
1 parent
7acf5d5
commit e4c193f
Showing
5 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
//! Progress rendering. | ||
|
||
mod config; | ||
pub mod nodeipc; | ||
pub mod simple; | ||
pub mod structured; | ||
mod unit; | ||
|
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use std::collections::HashMap; | ||
|
||
use progress_model::Registry; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use termwiz::surface::Change; | ||
|
||
use crate::RenderingConfig; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
struct IpcProgressBar { | ||
pub id: u64, | ||
pub topic: String, | ||
pub unit: String, | ||
pub total: u64, | ||
pub position: u64, | ||
pub parent_id: Option<u64>, | ||
} | ||
|
||
pub fn render(registry: &Registry, config: &RenderingConfig) -> Vec<Change> { | ||
let ipc = if let Some(ipc) = nodeipc::get_singleton() { | ||
ipc | ||
} else { | ||
tracing::trace!("nodeipc channel not available when rendering nodeipc progress bar"); | ||
return Vec::new(); | ||
}; | ||
|
||
let progress_bars: Vec<_> = registry | ||
.list_progress_bar() | ||
.into_iter() | ||
.filter(|pb| config.delay.as_millis() == 0 || pb.since_creation() >= config.delay) | ||
.map(|pb| { | ||
let (position, total) = pb.position_total(); | ||
IpcProgressBar { | ||
id: pb.id(), | ||
topic: pb.topic().to_owned(), | ||
unit: pb.unit().to_owned(), | ||
total, | ||
position, | ||
parent_id: pb.parent().map(|p| p.id()), | ||
} | ||
}) | ||
.collect(); | ||
|
||
if let Err(err) = ipc.send(HashMap::from([( | ||
"progress_bar_update".to_owned(), | ||
progress_bars, | ||
)])) { | ||
tracing::trace!("nodeipc send error on progress: {:?}", err); | ||
} | ||
|
||
Vec::new() | ||
} |