diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-04 11:44:50 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-04 11:44:56 +0100 |
commit | 2ef64316d1af14e36d7946ccdf64a2dd97202fc0 (patch) | |
tree | 932a1cad5185b002294eb46b87d0b4f07a485a6b /src/commands | |
parent | 746d46d57d39b2f32d8f02454463b03f64c16cdd (diff) |
Fix: Implementing jobs filtering only by env
Before this patch, one was only able to filter jobs by env if they were also
filtered by submit.
This patch fixes this by implementing env filtering for not-submit-filtered
jobs.
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/db.rs | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/commands/db.rs b/src/commands/db.rs index 0ef9893..349fa79 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -306,6 +306,11 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { "Env", ]); let conn = crate::db::establish_connection(conn_cfg)?; + let env_filter_tpl = matches + .value_of("filter_env") + .map(crate::util::env::parse_to_env) + .transpose()?; + let jobs = matches .value_of("submit_uuid") .map(uuid::Uuid::parse_str) @@ -316,46 +321,49 @@ fn jobs(conn_cfg: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { .inner_join(schema::endpoints::table) .inner_join(schema::packages::table) .left_outer_join(schema::job_envs::table.inner_join(schema::envvars::table)) - .filter(schema::submits::uuid.eq(&submit_uuid)); + .filter(schema::submits::uuid.eq(&submit_uuid)) + .into_boxed(); - if let Some((env_name, env_value)) = matches - .value_of("filter_env") - .map(crate::util::env::parse_to_env) - .transpose()? - { - sel.filter({ - use crate::diesel::BoolExpressionMethods; + let sel = if let Some((name, val)) = env_filter_tpl.as_ref() { + use crate::diesel::BoolExpressionMethods; - schema::envvars::dsl::name - .eq(env_name.as_ref()) - .and(schema::envvars::dsl::value.eq(env_value)) + sel.filter({ + schema::envvars::dsl::name.eq(name.as_ref()) + .and(schema::envvars::dsl::value.eq(val)) }) - .load::<( - models::Job, - models::Submit, - models::Endpoint, - models::Package, - Option<(models::JobEnv, models::EnvVar)>, - )>(&conn) - .map_err(Error::from) } else { - sel.load::<( + sel + }; + + sel.load::<( models::Job, models::Submit, models::Endpoint, models::Package, Option<(models::JobEnv, models::EnvVar)>, )>(&conn) - .map_err(Error::from) - } + .map_err(Error::from) }) .unwrap_or_else(|| { - dsl::jobs + let sel = dsl::jobs .inner_join(crate::schema::submits::table) .inner_join(crate::schema::endpoints::table) .inner_join(crate::schema::packages::table) .left_outer_join(schema::job_envs::table.inner_join(schema::envvars::table)) - .load::<( + .into_boxed(); + + let sel = if let Some((name, val)) = env_filter_tpl.as_ref() { + use crate::diesel::BoolExpressionMethods; + + sel.filter({ + schema::envvars::dsl::name.eq(name.as_ref()) + .and(schema::envvars::dsl::value.eq(val)) + }) + } else { + sel + }; + + sel.load::<( models::Job, models::Submit, models::Endpoint, |