Skip to content

Commit a53c40c

Browse files
committed
Yahoo client only fetches the latest news within a specific interval.
1 parent 55e975b commit a53c40c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

chloria-backend/chloria-job/src/infrastructure/news_fetcher/yahoo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ struct NewsResponseChannelItem {
3636

3737
pub(crate) struct YahooClient {
3838
providers: Vec<String>,
39+
interval: i64,
3940
}
4041

4142
impl YahooClient {
42-
pub(crate) fn new() -> Self {
43+
pub(crate) fn new(interval: i64) -> Self {
4344
Self {
4445
// TODO: Find a better way to retrieve the list of providers
4546
providers: vec![
@@ -742,6 +743,7 @@ impl YahooClient {
742743
.iter()
743744
.map(|p| p.to_string())
744745
.collect(),
746+
interval,
745747
}
746748
}
747749

@@ -767,7 +769,7 @@ impl YahooClient {
767769
Some(pub_date) => match DateTime::parse_from_rfc2822(&pub_date) {
768770
Ok(published_time) => {
769771
let published_time: DateTime<Local> = published_time.into();
770-
if (now - published_time).num_days() > 0 {
772+
if (now - published_time).num_hours() >= self.interval {
771773
continue;
772774
}
773775
Some(published_time)

chloria-backend/chloria-job/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async fn main() -> Result<()> {
4242
.collect::<Vec<_>>();
4343
let chloria_origin_bucket_name = env::var("CHLORIA_ORIGIN_BUCKET_NAME")?;
4444
let chloria_case_permits_num = env::var("CHLORIA_CASE_PERMITS_NUM")?.parse::<usize>().unwrap_or(10);
45+
let chloria_job_interval = env::var("CHLORIA_JOB_INTERVAL")?.parse()?; // In hours
4546
env_logger::init_from_env(Env::new().filter("CHLORIA_LOG"));
4647
// Initialize infrastructure
4748
let mut news_fetchers: Vec<Arc<dyn NewsFetcher>> = vec![];
@@ -52,7 +53,7 @@ async fn main() -> Result<()> {
5253
}
5354
}
5455
if chloria_news_fetchers.contains(&"yahoo".to_string()) {
55-
let yahoo_client = YahooClient::new();
56+
let yahoo_client = YahooClient::new(chloria_job_interval);
5657
news_fetchers.push(Arc::new(yahoo_client));
5758
}
5859
let reqwest_tool = ReqwestTool::new();

deployment-local/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ services:
5757
- CHLORIA_NEWS_FETCHERS=yahoo
5858
- CHLORIA_ORIGIN_BUCKET_NAME=origin
5959
- CHLORIA_CASE_PERMITS_NUM=10
60+
- CHLORIA_JOB_INTERVAL=12
6061
- CHLORIA_LOG=info
6162
volumes:
6263
- ../:/usr/src/chloria/

0 commit comments

Comments
 (0)