Skip to content

Commit cd0160b

Browse files
committed
[GitHub.issue_pr] Set timeouts
1 parent 1810d29 commit cd0160b

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/helper.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use tokio::process::Command;
88

99
use crate::prop;
1010

11+
pub const TIMEOUT: Duration = Duration::from_secs(60 * 3);
12+
1113
pub fn reqwest_client() -> anyhow::Result<reqwest::Client> {
1214
reqwest_client_with(identity)
1315
}
@@ -17,7 +19,7 @@ pub fn reqwest_client_with(
1719
) -> anyhow::Result<reqwest::Client> {
1820
configure(
1921
reqwest::ClientBuilder::new()
20-
.timeout(Duration::from_secs(60) * 3)
22+
.timeout(TIMEOUT)
2123
.default_headers(HeaderMap::from_iter([(
2224
header::USER_AGENT,
2325
HeaderValue::from_str(&prop::UserAgent::Logo.as_str()).unwrap(),

src/platform/github/source/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::{fmt, future::Future, pin::Pin};
22

33
use anyhow::{Ok, anyhow, ensure};
4+
use octocrab::Octocrab;
45
use serde::Deserialize;
56

67
use crate::{
78
config::{Accessor, Validator},
9+
helper::TIMEOUT,
810
platform::{PlatformMetadata, PlatformTraitStatic},
911
source::{Article, Articles, FetcherTrait, Status, StatusKind, StatusSource, User},
1012
};
@@ -35,6 +37,7 @@ impl fmt::Display for ConfigParams {
3537

3638
pub struct Fetcher {
3739
params: Accessor<ConfigParams>,
40+
instance: Octocrab,
3841
}
3942

4043
impl PlatformTraitStatic for Fetcher {
@@ -59,11 +62,18 @@ impl fmt::Display for Fetcher {
5962

6063
impl Fetcher {
6164
pub fn new(params: Accessor<ConfigParams>) -> Self {
62-
Self { params }
65+
let instance = Octocrab::builder()
66+
.set_connect_timeout(Some(TIMEOUT))
67+
.set_read_timeout(Some(TIMEOUT))
68+
.set_write_timeout(Some(TIMEOUT))
69+
.build()
70+
.map_err(|err| anyhow!("failed to build Octocrab instance: {err}"))
71+
.unwrap();
72+
Self { params, instance }
6373
}
6474

6575
async fn fetch_status_impl(&self) -> anyhow::Result<Status> {
66-
let issues_prs = fetch(&self.params.repo, &self.params.query).await?;
76+
let issues_prs = fetch(&self.instance, &self.params.repo, &self.params.query).await?;
6777

6878
Ok(Status::new(
6979
StatusKind::Articles(issues_prs),
@@ -75,8 +85,8 @@ impl Fetcher {
7585
}
7686
}
7787

78-
async fn fetch(repo: &str, query: &str) -> anyhow::Result<Articles> {
79-
let results = octocrab::instance()
88+
async fn fetch(instance: &Octocrab, repo: &str, query: &str) -> anyhow::Result<Articles> {
89+
let results = instance
8090
.search()
8191
.issues_and_pull_requests(&format!("repo:{repo} {query}"))
8292
.sort("created")

0 commit comments

Comments
 (0)