Skip to content

Commit b75231f

Browse files
committed
refactor: move download progress bar for tree sitter loader into CLI insted if codemod-sandbox
1 parent e8ca1de commit b75231f

File tree

17 files changed

+314
-111
lines changed

17 files changed

+314
-111
lines changed

Cargo.lock

Lines changed: 12 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ thiserror = "2.0"
5454
tokio = { version = "1.36", features = ["full"] }
5555
uuid = { version = "1.6", features = ["v4", "serde"] }
5656
walkdir = "2.4"
57+
indicatif = "0.17"
5758

5859
wasm-bindgen = { git = "https://github.com/mohebifar/wasm-bindgen.git", branch = "wasi" }
5960
wasm-bindgen-cli-support = { git = "https://github.com/mohebifar/wasm-bindgen.git", branch = "wasi" }

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ urlencoding = "2.1"
3838
humantime = "2.1"
3939
inquire = "0.7"
4040
console = "0.15"
41+
indicatif = { workspace = true }
4142

4243
# OIDC and HTTP dependencies
4344
reqwest = { version = "0.11", features = ["json", "rustls-tls", "multipart"] }

crates/cli/src/commands/jssg/run.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::download_progress_bar::create_progress_bar;
12
use anyhow::Result;
23
use clap::Args;
34
use codemod_sandbox::sandbox::{
@@ -123,8 +124,9 @@ pub async fn handler(args: &Command) -> Result<()> {
123124

124125
// Create and run the execution engine
125126
let engine = ExecutionEngine::new(config);
127+
let progress_callback = Some(create_progress_bar());
126128
let stats = engine
127-
.execute_on_directory(js_file_path, target_directory)
129+
.execute_on_directory(js_file_path, target_directory, progress_callback)
128130
.await?;
129131

130132
println!("Modified files: {:?}", stats.files_modified);

crates/cli/src/commands/run.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1+
use crate::auth_provider::CliAuthProvider;
2+
use crate::auth_provider::CliAuthProvider;
3+
use crate::auth_provider::CliAuthProvider;
4+
use crate::dirty_git_check;
5+
use crate::dirty_git_check;
6+
use crate::download_progress_bar::create_progress_bar;
7+
use crate::workflow_runner::{run_workflow, WorkflowRunConfig};
8+
use crate::workflow_runner::{run_workflow, WorkflowRunConfig};
19
use anyhow::Result;
10+
use butterflow_core::engine::{Engine, ProgressCallback};
11+
use butterflow_core::engine::{Engine, GLOBAL_STATS};
12+
use butterflow_core::registry::{RegistryClient, RegistryConfig, RegistryError};
13+
use butterflow_core::registry::{RegistryClient, RegistryConfig, RegistryError};
214
use butterflow_core::utils::get_cache_dir;
315
use clap::Args;
16+
use codemod_sandbox::sandbox::engine::ExecutionStats;
17+
use codemod_telemetry::send_event::{BaseEvent, TelemetrySender};
418
use log::info;
519
use rand::Rng;
620
use std::collections::HashMap;
721
use std::path::{Path, PathBuf};
822
use std::process::Command as ProcessCommand;
923
use tokio::sync::Mutex;
1024

11-
use crate::auth_provider::CliAuthProvider;
12-
use crate::dirty_git_check;
13-
use crate::workflow_runner::{run_workflow, WorkflowRunConfig};
14-
use butterflow_core::engine::{Engine, GLOBAL_STATS};
15-
use butterflow_core::registry::{RegistryClient, RegistryConfig, RegistryError};
16-
use codemod_sandbox::sandbox::engine::ExecutionStats;
17-
use codemod_telemetry::send_event::{BaseEvent, TelemetrySender};
18-
1925
#[derive(Args, Debug)]
2026
pub struct Command {
2127
/// Package name with optional version (e.g., @org/package@1.0.0)
@@ -100,13 +106,15 @@ pub async fn handler(
100106
resolved_package.package_dir.display()
101107
);
102108

109+
let progress_callback = Some(create_progress_bar());
103110
// Execute the codemod
104111
let stats = execute_codemod(
105112
engine,
106113
&resolved_package.package_dir,
107114
&args.path,
108115
&args.args,
109116
args.dry_run,
117+
progress_callback,
110118
)
111119
.await;
112120

@@ -194,6 +202,7 @@ async fn execute_codemod(
194202
target_path: &Path,
195203
additional_args: &[String],
196204
dry_run: bool,
205+
progress_callback: Option<ProgressCallback>,
197206
) -> Result<ExecutionStats> {
198207
let workflow_path = package_dir.join("workflow.yaml");
199208

@@ -230,7 +239,7 @@ async fn execute_codemod(
230239
};
231240

232241
// Run workflow using the extracted workflow runner
233-
run_workflow(engine, config).await?;
242+
run_workflow(engine, config, progress_callback).await?;
234243
let stats = GLOBAL_STATS
235244
.get_or_init(|| Mutex::new(ExecutionStats::default()))
236245
.lock()

crates/cli/src/commands/workflow/resume.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::download_progress_bar::create_progress_bar;
12
use anyhow::{Context, Result};
23
use butterflow_core::engine::Engine;
34
use butterflow_models::{Task, TaskStatus, WorkflowStatus};
@@ -27,15 +28,15 @@ pub async fn handler(engine: &Engine, args: &Command) -> Result<()> {
2728
if args.trigger_all {
2829
// Trigger all awaiting tasks
2930
engine
30-
.trigger_all(args.id)
31+
.trigger_all(args.id, Some(create_progress_bar()))
3132
.await
3233
.context("Failed to trigger all tasks")?;
3334

3435
info!("Triggered all awaiting tasks");
3536
} else if !args.task.is_empty() {
3637
// Trigger specific tasks
3738
engine
38-
.resume_workflow(args.id, args.task.to_vec())
39+
.resume_workflow(args.id, args.task.to_vec(), Some(create_progress_bar()))
3940
.await
4041
.context("Failed to resume workflow")?;
4142

crates/cli/src/commands/workflow/run.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use crate::dirty_git_check;
2+
use crate::download_progress_bar::create_progress_bar;
3+
use crate::workflow_runner::{resolve_workflow_source, run_workflow, WorkflowRunConfig};
14
use anyhow::{Context, Result};
25
use butterflow_core::engine::Engine;
36
use butterflow_core::utils;
47
use clap::Args;
58

6-
use crate::dirty_git_check;
7-
use crate::workflow_runner::{resolve_workflow_source, run_workflow, WorkflowRunConfig};
8-
99
#[derive(Args, Debug)]
1010
pub struct Command {
1111
/// Path to workflow file or directory
@@ -40,7 +40,7 @@ pub async fn handler(engine: &Engine, args: &Command) -> Result<()> {
4040
dirty_git_check::dirty_check(args.allow_dirty)?;
4141

4242
// Run workflow using the extracted workflow runner
43-
run_workflow(engine, config).await?;
43+
run_workflow(engine, config, Some(create_progress_bar())).await?;
4444

4545
Ok(())
4646
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
2+
use std::sync::Arc;
3+
4+
pub fn create_progress_bar() -> Arc<Box<dyn Fn(u64, u64) + Send + Sync>> {
5+
let progress_bar = Arc::new(std::sync::Mutex::new(None::<ProgressBar>));
6+
let progress_bar = Arc::clone(&progress_bar);
7+
Arc::new(Box::new(move |downloaded: u64, total: u64| {
8+
let mut pb_guard = progress_bar.lock().unwrap();
9+
if pb_guard.is_none() && total > 0 {
10+
let pb = ProgressBar::new(total);
11+
pb.set_style(
12+
ProgressStyle::with_template(
13+
"{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})"
14+
)
15+
.unwrap()
16+
.with_key("eta", |state: &ProgressState, w: &mut dyn std::fmt::Write| {
17+
write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()
18+
})
19+
.progress_chars("#>-")
20+
);
21+
*pb_guard = Some(pb);
22+
}
23+
if let Some(ref pb) = *pb_guard {
24+
pb.set_position(downloaded);
25+
if downloaded >= total {
26+
pb.finish_with_message("Downloaded successfully");
27+
}
28+
}
29+
}))
30+
}

crates/cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod auth;
66
mod auth_provider;
77
mod commands;
88
mod dirty_git_check;
9+
mod download_progress_bar;
910
mod engine;
1011
mod workflow_runner;
1112
use ascii_art::print_ascii_art;

crates/cli/src/workflow_runner.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::{Context, Result};
2-
use butterflow_core::engine::Engine;
2+
use butterflow_core::engine::{Engine, ProgressCallback};
33
use butterflow_core::utils;
44
use butterflow_models::{Task, TaskStatus, WorkflowStatus};
55
use log::{error, info};
@@ -16,7 +16,11 @@ pub struct WorkflowRunConfig {
1616
}
1717

1818
/// Run a workflow with the given configuration
19-
pub async fn run_workflow(engine: &Engine, config: WorkflowRunConfig) -> Result<String> {
19+
pub async fn run_workflow(
20+
engine: &Engine,
21+
config: WorkflowRunConfig,
22+
progress_callback: Option<ProgressCallback>,
23+
) -> Result<String> {
2024
// Parse workflow file
2125
let workflow = utils::parse_workflow_file(&config.workflow_file_path).context(format!(
2226
"Failed to parse workflow file: {}",
@@ -25,7 +29,12 @@ pub async fn run_workflow(engine: &Engine, config: WorkflowRunConfig) -> Result<
2529

2630
// Run workflow
2731
let workflow_run_id = engine
28-
.run_workflow(workflow, config.params, Some(config.bundle_path))
32+
.run_workflow(
33+
workflow,
34+
config.params,
35+
Some(config.bundle_path),
36+
progress_callback,
37+
)
2938
.await
3039
.context("Failed to run workflow")?;
3140

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy