diff --git a/fetcher-config/src/jobs/task.rs b/fetcher-config/src/jobs/task.rs index c2d2e0a..8e380e2 100644 --- a/fetcher-config/src/jobs/task.rs +++ b/fetcher-config/src/jobs/task.rs @@ -54,7 +54,7 @@ impl Task { match external.read_filter(job, task_name, expected_rf_type) { ExternalDataResult::Ok(rf) => Some(Arc::new(RwLock::new(rf))), ExternalDataResult::Unavailable => { - tracing::warn!("Read filter is unavailable, skipping"); + tracing::info!("Read filter is unavailable, skipping"); None } ExternalDataResult::Err(e) => return Err(e.into()), @@ -94,7 +94,7 @@ impl Task { match external.entry_to_msg_map(job, task_name) { ExternalDataResult::Ok(v) => Some(v), ExternalDataResult::Unavailable => { - tracing::warn!("Entry to message map is unavailable, skipping..."); + tracing::info!("Entry to message map is unavailable, skipping..."); None } ExternalDataResult::Err(e) => return Err(e.into()), diff --git a/fetcher/src/args.rs b/fetcher/src/args.rs index 433ddf0..d21bc32 100644 --- a/fetcher/src/args.rs +++ b/fetcher/src/args.rs @@ -4,12 +4,15 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use either::Either; -use fetcher_config::jobs::named::{JobName, JobWithTaskNames}; +use crate::settings::{context::StaticContext, external_data_provider::ExternalDataFromDataDir}; +use fetcher_config::jobs::{ + named::{JobName, JobWithTaskNames}, + Job as ConfigJob, +}; use argh::FromArgs; -use color_eyre::{eyre::eyre, Report}; -use std::{iter, path::PathBuf, str::FromStr}; +use color_eyre::{eyre::eyre, Report, Result}; +use std::{path::PathBuf, str::FromStr}; /// Automatic news fetching and parsing #[derive(FromArgs, Debug)] @@ -128,47 +131,40 @@ impl FromStr for Setting { /// Wrapper around Job foreign struct to implement `FromStr` from valid job JSON #[derive(Debug)] -pub struct JsonJobs(pub Vec<(JobName, JobWithTaskNames)>); +pub struct JsonJobs(Vec<(JobName, ConfigJob)>); impl FromStr for JsonJobs { type Err = Report; fn from_str(s: &str) -> Result { - use fetcher_config::jobs::external_data::ProvideExternalData; - use fetcher_core::read_filter::ReadFilter; - - struct EmptyExternalData; - - // TODO: add a way to provide external settings even in manual jobs - impl ProvideExternalData for EmptyExternalData { - // it's a lie but don't tell anybody... - type ReadFilter = Box; - } - // HACK: if the input is a JSON array - let config_jobs = if s - .chars() - .next() - .ok_or_else(|| eyre!("Manual job JSON is empty"))? - == '[' - { + let config_jobs = if s.chars().next().expect("Manual job JSON is empty") == '[' { let v: Vec = serde_json::from_str(s)?; - Either::Left( - v.into_iter() - .enumerate() - // use the index as the job name - .map(|(idx, job)| ((idx + 1).to_string(), job)), - ) + v.into_iter() + .enumerate() + // use the index as the job name + .map(|(idx, job)| ((idx + 1).to_string().into(), job)) + .collect() } else { let job: fetcher_config::jobs::Job = serde_json::from_str(s)?; // just use "Manual" as the job name - Either::Right(iter::once(("Manual".to_owned(), job))) + vec![("Manual".to_owned().into(), job)] }; - let jobs: Result, _> = config_jobs - .map(|(name, job)| job.parse(name.into(), &EmptyExternalData)) - .collect(); + Ok(Self(config_jobs)) + } +} - Ok(Self(jobs?)) +impl JsonJobs { + pub fn parse( + self, + cx: StaticContext, + ) -> Result> { + Ok(self + .0 + .into_iter() + .map(|(name, config)| config.parse(name, &ExternalDataFromDataDir { cx })) + .collect::, _>>()? + .into_iter()) } } diff --git a/fetcher/src/main.rs b/fetcher/src/main.rs index 43bc712..7fd4b55 100644 --- a/fetcher/src/main.rs +++ b/fetcher/src/main.rs @@ -114,7 +114,7 @@ async fn async_main() -> Result<()> { Some(args::TopLvlSubcommand::Run(run_args)) => run_command(run_args, cx).await, None => run_command(args::Run::default(), cx).await, Some(args::TopLvlSubcommand::RunManual(args::RunManual { jobs })) => { - run_jobs(jobs.0.into_iter(), ErrorHandling::Forward, cx).await?; + run_jobs(jobs.parse(cx)?, ErrorHandling::Forward, cx).await?; Ok(()) }