progress: Let's just call them "tasks" instead of "processes"...

This commit is contained in:
Zhaofeng Li 2021-02-10 10:38:03 -08:00
parent 9d59a6a288
commit 62753ea138
8 changed files with 42 additions and 42 deletions

View file

@ -145,7 +145,7 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) {
None => None,
};
let progress = progress.create_process_progress(name.clone());
let progress = progress.create_task_progress(name.clone());
let command_v: Vec<&str> = command.iter().map(|s| s.as_str()).collect();
let command = host.ssh(&command_v);

View file

@ -6,7 +6,7 @@ use futures::future::join_all;
use tokio::sync::{Mutex, Semaphore};
use super::{Hive, Host, CopyOptions, NodeConfig, Profile, StoreDerivation, ProfileMap, host};
use crate::progress::{Progress, ProcessProgress, OutputStyle};
use crate::progress::{Progress, TaskProgress, OutputStyle};
/// Amount of RAM reserved for the system, in MB.
const EVAL_RESERVE_MB: u64 = 1024;
@ -19,11 +19,11 @@ const BATCH_OPERATION_LABEL: &'static str = "(...)";
macro_rules! set_up_batch_progress_bar {
($progress:ident, $style:ident, $chunk:ident, $single_text:expr, $batch_text:expr) => {{
if $chunk.len() == 1 {
let mut bar = $progress.create_process_progress($chunk[0].to_string());
let mut bar = $progress.create_task_progress($chunk[0].to_string());
bar.log($single_text);
bar
} else {
let mut bar = $progress.create_process_progress(BATCH_OPERATION_LABEL.to_string());
let mut bar = $progress.create_task_progress(BATCH_OPERATION_LABEL.to_string());
bar.log(&format!($batch_text, $chunk.len()));
bar
}
@ -276,12 +276,12 @@ impl Deployment {
let progress = progress.clone();
futures.push(async move {
let permit = arc_self.parallelism_limit.apply.acquire().await.unwrap();
let mut process = progress.create_process_progress(node.clone());
let mut task = progress.create_task_progress(node.clone());
process.log("Uploading keys...");
task.log("Uploading keys...");
if let Err(e) = target.host.upload_keys(&target.config.keys).await {
process.failure(&format!("Failed to upload keys: {}", e));
task.failure(&format!("Failed to upload keys: {}", e));
let mut results = arc_self.results.lock().await;
let stage = Stage::Apply(node.to_string());
@ -289,7 +289,7 @@ impl Deployment {
results.push(DeploymentResult::failure(stage, logs));
return;
} else {
process.success("Keys uploaded");
task.success("Keys uploaded");
}
drop(permit);
@ -424,7 +424,7 @@ impl Deployment {
}
}
async fn eval_profiles(self: Arc<Self>, chunk: &Vec<String>, progress: ProcessProgress) -> Option<StoreDerivation<ProfileMap>> {
async fn eval_profiles(self: Arc<Self>, chunk: &Vec<String>, progress: TaskProgress) -> Option<StoreDerivation<ProfileMap>> {
let (eval, logs) = self.hive.eval_selected(&chunk, progress.clone()).await;
match eval {
@ -443,7 +443,7 @@ impl Deployment {
}
}
async fn build_profiles(self: Arc<Self>, chunk: &Vec<String>, derivation: StoreDerivation<ProfileMap>, progress: ProcessProgress) -> Option<ProfileMap> {
async fn build_profiles(self: Arc<Self>, chunk: &Vec<String>, derivation: StoreDerivation<ProfileMap>, progress: TaskProgress) -> Option<ProfileMap> {
// FIXME: Remote build?
let mut builder = host::local();
@ -475,7 +475,7 @@ impl Deployment {
async fn apply_profile(self: Arc<Self>, name: &str, mut target: Target, profile: Profile, multi: Arc<Progress>) {
let permit = self.parallelism_limit.apply.acquire().await.unwrap();
let mut bar = multi.create_process_progress(name.to_string());
let mut bar = multi.create_task_progress(name.to_string());
if self.options.upload_keys && !target.config.keys.is_empty() {
bar.log("Uploading keys...");

View file

@ -15,7 +15,7 @@ use super::{
};
use super::NixCommand;
use crate::util::CommandExecution;
use crate::progress::ProcessProgress;
use crate::progress::TaskProgress;
const HIVE_EVAL: &'static [u8] = include_bytes!("eval.nix");
@ -67,7 +67,7 @@ impl Hive {
/// Evaluation may take up a lot of memory, so we make it possible
/// to split up the evaluation process into chunks and run them
/// concurrently with other processes (e.g., build and apply).
pub async fn eval_selected(&self, nodes: &Vec<String>, progress_bar: ProcessProgress) -> (NixResult<StoreDerivation<ProfileMap>>, Option<String>) {
pub async fn eval_selected(&self, nodes: &Vec<String>, progress_bar: TaskProgress) -> (NixResult<StoreDerivation<ProfileMap>>, Option<String>) {
// FIXME: The return type is ugly...
let nodes_expr = SerializedNixExpresssion::new(nodes);

View file

@ -10,7 +10,7 @@ use tempfile::NamedTempFile;
use super::{CopyDirection, CopyOptions, Host};
use crate::nix::{StorePath, Profile, Goal, NixResult, NixCommand, Key, SYSTEM_PROFILE};
use crate::util::CommandExecution;
use crate::progress::ProcessProgress;
use crate::progress::TaskProgress;
/// The local machine running Colmena.
///
@ -18,14 +18,14 @@ use crate::progress::ProcessProgress;
/// (e.g., building Linux derivations on macOS).
#[derive(Debug)]
pub struct Local {
progress_bar: ProcessProgress,
progress_bar: TaskProgress,
logs: String,
}
impl Local {
pub fn new() -> Self {
Self {
progress_bar: ProcessProgress::default(),
progress_bar: TaskProgress::default(),
logs: String::new(),
}
}
@ -94,7 +94,7 @@ impl Host for Local {
result
}
fn set_progress_bar(&mut self, bar: ProcessProgress) {
fn set_progress_bar(&mut self, bar: TaskProgress) {
self.progress_bar = bar;
}
async fn dump_logs(&self) -> Option<&str> {

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use async_trait::async_trait;
use super::{StorePath, Profile, Goal, NixResult, NixError, Key};
use crate::progress::ProcessProgress;
use crate::progress::TaskProgress;
mod ssh;
pub use ssh::Ssh;
@ -109,8 +109,8 @@ pub trait Host: Send + Sync + std::fmt::Debug {
}
#[allow(unused_variables)]
/// Provides a ProcessProgress to use during operations.
fn set_progress_bar(&mut self, bar: ProcessProgress) {
/// Provides a TaskProgress to use during operations.
fn set_progress_bar(&mut self, bar: TaskProgress) {
}
/// Dumps human-readable unstructured log messages related to the host.

View file

@ -11,7 +11,7 @@ use tokio::io::{AsyncWriteExt, BufReader};
use super::{CopyDirection, CopyOptions, Host};
use crate::nix::{StorePath, Profile, Goal, NixResult, NixCommand, NixError, Key, SYSTEM_PROFILE};
use crate::util::{CommandExecution, capture_stream};
use crate::progress::ProcessProgress;
use crate::progress::TaskProgress;
const DEPLOY_KEY_TEMPLATE: &'static str = include_str!("./deploy-key.template");
@ -32,7 +32,7 @@ pub struct Ssh {
friendly_name: String,
path_cache: HashSet<StorePath>,
progress_bar: ProcessProgress,
progress_bar: TaskProgress,
logs: String,
}
@ -74,7 +74,7 @@ impl Host for Ssh {
let command = self.ssh(&v);
self.run_command(command).await
}
fn set_progress_bar(&mut self, bar: ProcessProgress) {
fn set_progress_bar(&mut self, bar: TaskProgress) {
self.progress_bar = bar;
}
async fn dump_logs(&self) -> Option<&str> {
@ -92,7 +92,7 @@ impl Ssh {
ssh_config: None,
friendly_name,
path_cache: HashSet::new(),
progress_bar: ProcessProgress::default(),
progress_bar: TaskProgress::default(),
logs: String::new(),
}
}

View file

@ -72,9 +72,9 @@ impl Progress {
self.label_width = width;
}
/// Returns a handle for a process to display progress information.
pub fn create_process_progress(&self, label: String) -> ProcessProgress {
let mut progress = ProcessProgress::new(label.clone(), self.label_width);
/// Returns a handle for a task to display progress information.
pub fn create_task_progress(&self, label: String) -> TaskProgress {
let mut progress = TaskProgress::new(label.clone(), self.label_width);
if let Some(multi) = self.multi.as_ref() {
let bar = multi.add(IndicatifBar::new(100));
@ -89,7 +89,7 @@ impl Progress {
progress
}
/// Runs code that may initate multiple processes.
/// Runs code that may initate multiple tasks.
pub async fn run<F: Future, U>(self: Arc<Self>, func: U) -> F::Output
where U: FnOnce(Arc<Progress>) -> F
{
@ -146,16 +146,16 @@ impl Default for Progress {
}
}
/// Progress display for a single process.
/// Progress display for a single task.
#[derive(Debug, Clone)]
pub struct ProcessProgress {
pub struct TaskProgress {
label: String,
label_width: usize,
bar: Option<IndicatifBar>,
quiet: bool,
}
impl ProcessProgress {
impl TaskProgress {
fn new(label: String, label_width: usize) -> Self {
Self {
label,
@ -183,7 +183,7 @@ impl ProcessProgress {
}
}
/// Marks the process as successful, consuming the spinner.
/// Marks the task as successful and leave the spinner intact.
pub fn success(self, message: &str) {
if self.quiet {
return;
@ -197,7 +197,7 @@ impl ProcessProgress {
}
}
/// Marks the process as successful, consuming the spinner.
/// Marks the task as successful and remove the spinner.
pub fn success_quiet(self) {
if self.quiet {
return;
@ -208,7 +208,7 @@ impl ProcessProgress {
}
}
/// Marks the process as unsuccessful, consuming the spinner.
/// Marks the task as unsuccessful.
pub fn failure(self, message: &str) {
if self.quiet {
return;
@ -229,8 +229,8 @@ impl ProcessProgress {
}
}
impl Default for ProcessProgress {
/// Creates a ProcessProgress that does nothing.
impl Default for TaskProgress {
/// Creates a TaskProgress that does nothing.
fn default() -> Self {
Self {
label: String::new(),

View file

@ -10,7 +10,7 @@ use tokio::io::{AsyncRead, AsyncBufReadExt, BufReader};
use tokio::process::Command;
use super::nix::{NodeConfig, Hive, NixResult, NixError};
use super::progress::ProcessProgress;
use super::progress::TaskProgress;
enum NodeFilter {
NameFilter(GlobPattern),
@ -20,7 +20,7 @@ enum NodeFilter {
/// Non-interactive execution of an arbitrary Nix command.
pub struct CommandExecution {
command: Command,
progress_bar: ProcessProgress,
progress_bar: TaskProgress,
stdout: Option<String>,
stderr: Option<String>,
}
@ -29,14 +29,14 @@ impl CommandExecution {
pub fn new(command: Command) -> Self {
Self {
command,
progress_bar: ProcessProgress::default(),
progress_bar: TaskProgress::default(),
stdout: None,
stderr: None,
}
}
/// Provides a ProcessProgress to use to display output.
pub fn set_progress_bar(&mut self, bar: ProcessProgress) {
/// Provides a TaskProgress to use to display output.
pub fn set_progress_bar(&mut self, bar: TaskProgress) {
self.progress_bar = bar;
}
@ -215,7 +215,7 @@ fn canonicalize_cli_path(path: String) -> PathBuf {
}
}
pub async fn capture_stream<R: AsyncRead + Unpin>(mut stream: BufReader<R>, mut progress_bar: ProcessProgress) -> String {
pub async fn capture_stream<R: AsyncRead + Unpin>(mut stream: BufReader<R>, mut progress_bar: TaskProgress) -> String {
let mut log = String::new();
loop {