diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-07 15:39:00 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-07 15:39:00 +0200 |
commit | 810cc1c8281be8437ae0fd6257b2ea6190fe8d24 (patch) | |
tree | 33d458bce8c87e5adebf8fae64408a48468ecd27 | |
parent | 5e4107b554678dc7191631516a2ec5f5efdc416c (diff) | |
parent | 51b70e647230fb6df95dd3b0d35ce77409e73afb (diff) |
Merge branch 'db-jobs-flags'
-rw-r--r-- | src/cli.rs | 24 | ||||
-rw-r--r-- | src/commands/db.rs | 49 |
2 files changed, 53 insertions, 20 deletions
@@ -289,6 +289,30 @@ pub fn cli<'a>() -> App<'a> { .value_name("LIMIT") .about("Only list newest LIMIT jobs instead of all") ) + + .arg(arg_older_than_date("List only jobs older than DATE")) + .arg(arg_newer_than_date("List only jobs newer than DATE")) + + .arg(Arg::new("endpoint") + .required(false) + .multiple(false) + .long("endpoint") + .short('e') + .takes_value(true) + .value_name("ENDPOINT") + .about("Only show jobs from ENDPOINT") + ) + + .arg(Arg::new("package") + .required(false) + .multiple(false) + .long("package") + .short('p') + .takes_value(true) + .value_name("PKG") + .about("Only show jobs for PKG") + ) + ) .subcommand(App::new("job") diff --git a/src/commands/db.rs b/src/commands/db.rs index d750ede..08ed6c8 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -32,6 +32,7 @@ use log::debug; use log::info; use log::trace; +use crate::commands::util::get_date_filter; use crate::config::Configuration; use crate::db::DbConnectionConfig; use crate::db::models; @@ -411,28 +412,24 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { "Version", ]); let conn = conn_cfg.establish_connection()?; + let older_than_filter = get_date_filter("older_than", matches)?; + let newer_than_filter = get_date_filter("newer_than", matches)?; - let sel = schema::jobs::table + let mut sel = schema::jobs::table .inner_join(schema::submits::table) .inner_join(schema::endpoints::table) .inner_join(schema::packages::table) .into_boxed(); - let sel = if let Some(submit_uuid) = matches - .value_of("submit_uuid") - .map(uuid::Uuid::parse_str) - .transpose()? - { - sel.filter(schema::submits::uuid.eq(submit_uuid)) - } else { - sel - }; + if let Some(submit_uuid) = matches.value_of("submit_uuid").map(uuid::Uuid::parse_str).transpose()? { + sel = sel.filter(schema::submits::uuid.eq(submit_uuid)) + } // Filter for environment variables from the CLI // // If we get a filter for environment on CLI, we fetch all job ids that are associated with the // passed environment variables and make `sel` filter for those. - let sel = if let Some((name, val)) = matches.value_of("env_filter").map(crate::util::env::parse_to_env).transpose()? { + if let Some((name, val)) = matches.value_of("env_filter").map(crate::util::env::parse_to_env).transpose()? { debug!("Filtering for ENV: {} = {}", name, val); let jids = schema::envvars::table .filter({ @@ -445,16 +442,28 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { .load::<i32>(&conn)?; debug!("Filtering for these IDs (because of env filter): {:?}", jids); - sel.filter(schema::jobs::dsl::id.eq_any(jids)) - } else { - sel - }; + sel = sel.filter(schema::jobs::dsl::id.eq_any(jids)); + } - let sel = if let Some(limit) = matches.value_of("limit").map(i64::from_str).transpose()? { - sel.limit(limit) - } else { - sel - }; + if let Some(datetime) = older_than_filter.as_ref() { + sel = sel.filter(schema::submits::dsl::submit_time.lt(datetime)) + } + + if let Some(datetime) = newer_than_filter.as_ref() { + sel = sel.filter(schema::submits::dsl::submit_time.gt(datetime)) + } + + if let Some(limit) = matches.value_of("limit").map(i64::from_str).transpose()? { + sel = sel.limit(limit) + } + + if let Some(ep_name) = matches.value_of("endpoint") { + sel = sel.filter(schema::endpoints::name.eq(ep_name)) + } + + if let Some(pkg_name) = matches.value_of("package") { + sel = sel.filter(schema::packages::name.eq(pkg_name)) + } let data = sel .order_by(schema::jobs::id.desc()) // required for the --limit implementation |