diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-07 14:19:01 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-07 15:38:53 +0200 |
commit | 8f9c7d77acfa16ebe9660eba113fbebd68b96eed (patch) | |
tree | 24ffb7aa08f0f42d44bfcd7be9c023920765714a | |
parent | 16c9a639b2ff340abb4c79c751ac06b55003fd93 (diff) |
Add date-filtering to "db jobs" subcommand
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/cli.rs | 3 | ||||
-rw-r--r-- | src/commands/db.rs | 11 |
2 files changed, 14 insertions, 0 deletions
@@ -289,6 +289,9 @@ 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")) ) .subcommand(App::new("job") diff --git a/src/commands/db.rs b/src/commands/db.rs index ed8fdae..4ece20a 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,6 +412,8 @@ 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 mut sel = schema::jobs::table .inner_join(schema::submits::table) @@ -442,6 +445,14 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { sel = sel.filter(schema::jobs::dsl::id.eq_any(jids)); } + 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) } |