Skip to content

Commit

Permalink
Control intervals from the command-line
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Feb 25, 2020
1 parent 2270261 commit d478bc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions criner/src/engine/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ pub async fn non_blocking(
io_bound_processors: u32,
cpu_bound_processors: u32,
cpu_o_bound_processors: u32,
fetch_every: Duration,
process_and_report_every: Duration,
assets_dir: PathBuf,
pool: impl Spawn + Clone + Send + 'static + Sync,
tokio: tokio::runtime::Handle,
) -> Result<()> {
check(deadline)?;

let interval_s = 60;
pool.spawn(
repeat_every_s(
interval_s,
fetch_every.as_secs() as u32,
{
let p = progress.clone();
move || p.add_child("Fetch Timer")
Expand All @@ -62,9 +63,8 @@ pub async fn non_blocking(
.map(|_| ()),
)?;

let interval_s = 10;
repeat_every_s(
interval_s,
process_and_report_every.as_secs() as u32,
{
let p = progress.clone();
move || p.add_child("Processing Timer")
Expand Down Expand Up @@ -113,6 +113,8 @@ pub fn blocking(
io_bound_processors: u32,
cpu_bound_processors: u32,
cpu_o_bound_processors: u32,
fetch_every: Duration,
process_and_report_every: Duration,
root: prodash::Tree,
gui: Option<prodash::tui::TuiOptions>,
) -> Result<()> {
Expand Down Expand Up @@ -149,6 +151,8 @@ pub fn blocking(
io_bound_processors,
cpu_bound_processors,
cpu_o_bound_processors,
fetch_every,
process_and_report_every,
assets_dir,
task_pool.clone(),
tokio_rt.handle().clone(),
Expand Down
8 changes: 8 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ pub enum SubCommands {
#[structopt(long, short = "t")]
time_limit: Option<humantime::Duration>,

/// The time between each fetch operation, specified in humantime, like 10s, 5min, or 2h, or '3h 2min 2s'
#[structopt(long, short = "f", default_value = "60s")]
fetch_every: humantime::Duration,

/// The time between each processing run, specified in humantime, like 10s, 5min, or 2h, or '3h 2min 2s'
#[structopt(long, short = "p", default_value = "60s")]
process_and_report_every: humantime::Duration,

/// Path to the possibly existing database. It's used to persist all mining results.
db_path: PathBuf,
},
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{ops::Add, path::PathBuf};
mod args;
pub mod error;
pub use args::*;
use std::time::Duration;

pub fn run_blocking(args: Parsed) -> criner::error::Result<()> {
use SubCommands::*;
Expand All @@ -15,6 +16,8 @@ pub fn run_blocking(args: Parsed) -> criner::error::Result<()> {
cpu_o_bound_processors: 10,
repository: None,
time_limit: None,
fetch_every: Duration::from_secs(60).into(),
process_and_report_every: Duration::from_secs(60).into(),
db_path: PathBuf::from("criner.db"),
});
match cmd {
Expand All @@ -30,6 +33,8 @@ pub fn run_blocking(args: Parsed) -> criner::error::Result<()> {
cpu_o_bound_processors,
no_gui,
progress_message_scrollback_buffer_size,
fetch_every,
process_and_report_every,
} => criner::run::blocking(
db_path,
repository
Expand All @@ -38,6 +43,8 @@ pub fn run_blocking(args: Parsed) -> criner::error::Result<()> {
io_bound_processors,
cpu_bound_processors,
cpu_o_bound_processors,
fetch_every.into(),
process_and_report_every.into(),
criner::prodash::TreeOptions {
message_buffer_capacity: progress_message_scrollback_buffer_size,
..criner::prodash::TreeOptions::default()
Expand Down

0 comments on commit d478bc5

Please sign in to comment.