Skip to content

Commit 4d24411

Browse files
committed
add timeout
1 parent e036fcf commit 4d24411

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/github/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ pub struct Scraper {
2626
gh: Arc<Github>,
2727
data: Data,
2828
finished: Arc<AtomicBool>,
29+
timeout: Option<u64>,
2930
}
3031

3132
impl Scraper {
3233
pub fn new(config: Config, data: Data) -> Self {
34+
let timeout = config.timeout;
3335
let gh = Github::new(config);
3436

3537
let finished = Arc::new(AtomicBool::new(false));
@@ -45,6 +47,7 @@ impl Scraper {
4547
gh: Arc::new(gh),
4648
data,
4749
finished,
50+
timeout
4851
}
4952
}
5053

@@ -97,7 +100,12 @@ impl Scraper {
97100

98101
loop {
99102
let start_loop = Instant::now();
100-
// TODO check timeout
103+
if let Some(timeout) = self.timeout {
104+
if start.elapsed() >= Duration::from_secs(timeout) {
105+
info!("Timeout reached, stopped scraping");
106+
break;
107+
}
108+
}
101109

102110
let mut repos = self.gh.scrape_repositories(last_id).await?;
103111
let mut js = JoinSet::new();

0 commit comments

Comments
 (0)