Skip to content

Commit

Permalink
Merge pull request #1705 from matter-labs/il-refactor-prover-cli-stat…
Browse files Browse the repository at this point in the history
…us-cmd
  • Loading branch information
ilitteri authored Apr 17, 2024
2 parents b3051b2 + 3fe32b6 commit d43dd15
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 47 deletions.
22 changes: 0 additions & 22 deletions prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions prover/prover_cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{command, Parser, Subcommand};

use crate::commands::{get_file_info, jobs_status};
use crate::commands::{self, get_file_info, status};

pub const VERSION_STRING: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -14,14 +14,15 @@ struct ProverCLI {
#[derive(Subcommand)]
enum ProverCommand {
FileInfo(get_file_info::Args),
StatusJobs(jobs_status::Args),
#[command(subcommand)]
Status(commands::StatusCommand),
}

pub async fn start() -> anyhow::Result<()> {
let ProverCLI { command } = ProverCLI::parse();
match command {
ProverCommand::FileInfo(args) => get_file_info::run(args).await?,
ProverCommand::StatusJobs(args) => jobs_status::run(args).await?,
ProverCommand::Status(status_cmd) => status::run(status_cmd).await?,
};

Ok(())
Expand Down
10 changes: 9 additions & 1 deletion prover/prover_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
use clap::Subcommand;
use status::jobs;

pub(crate) mod get_file_info;
pub(crate) mod jobs_status;
pub(crate) mod status;

#[derive(Subcommand)]
pub(crate) enum StatusCommand {
Jobs(jobs::Args),
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@ pub(crate) struct Args {
verbose: bool,
}

fn pretty_print_job_status(
l1_batch_number: &L1BatchNumber,
statistics: &JobCountStatistics,
verbose: bool,
) {
let total_jobs =
statistics.queued + statistics.in_progress + statistics.failed + statistics.successful;
let progress = (statistics.successful as f32 / total_jobs as f32) * 100.0;
println!("Batch number: {}", l1_batch_number);
println!(
"Progress: {:.2}% ({}/{})",
progress, statistics.successful, total_jobs
);
if verbose {
println!("In progress: {}", statistics.in_progress);
println!("Queued: {}", statistics.in_progress);
println!("Successful: {}", statistics.in_progress);
}
println!("Failed: {}", statistics.failed);
}

pub(crate) async fn run(args: Args) -> anyhow::Result<()> {
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;

Expand Down Expand Up @@ -61,3 +40,24 @@ pub(crate) async fn run(args: Args) -> anyhow::Result<()> {
}
Ok(())
}

fn pretty_print_job_status(
l1_batch_number: &L1BatchNumber,
statistics: &JobCountStatistics,
verbose: bool,
) {
let total_jobs =
statistics.queued + statistics.in_progress + statistics.failed + statistics.successful;
let progress = (statistics.successful as f32 / total_jobs as f32) * 100.0;
println!("Batch number: {}", l1_batch_number);
println!(
"Progress: {:.2}% ({}/{})",
progress, statistics.successful, total_jobs
);
if verbose {
println!("In progress: {}", statistics.in_progress);
println!("Queued: {}", statistics.in_progress);
println!("Successful: {}", statistics.in_progress);
}
println!("Failed: {}", statistics.failed);
}
9 changes: 9 additions & 0 deletions prover/prover_cli/src/commands/status/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use super::StatusCommand;

pub(crate) mod jobs;

pub(crate) async fn run(status_cmd: StatusCommand) -> anyhow::Result<()> {
match status_cmd {
StatusCommand::Jobs(args) => jobs::run(args).await,
}
}
2 changes: 2 additions & 0 deletions prover/prover_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use prover_cli::cli;
#[tokio::main]
async fn main() {
env_logger::builder()
.filter_module("zksync_db_connection::connection_pool", log::LevelFilter::Off)
.filter_module("sqlx::query", log::LevelFilter::Off)
.filter_level(log::LevelFilter::Debug)
.init();

Expand Down

0 comments on commit d43dd15

Please sign in to comment.