Skip to content

Commit

Permalink
add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
NULLx76 committed Oct 21, 2024
1 parent e036fcf commit f83b35e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ pub struct Scraper {
gh: Arc<Github>,
data: Data,
finished: Arc<AtomicBool>,
timeout: Option<u64>,
}

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

let finished = Arc::new(AtomicBool::new(false));
Expand All @@ -45,6 +47,7 @@ impl Scraper {
gh: Arc::new(gh),
data,
finished,
timeout,
}
}

Expand Down Expand Up @@ -97,7 +100,12 @@ impl Scraper {

loop {
let start_loop = Instant::now();
// TODO check timeout
if let Some(timeout) = self.timeout {
if start.elapsed() >= Duration::from_secs(timeout) {
info!("Timeout reached, stopped scraping");
break;
}
}

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

0 comments on commit f83b35e

Please sign in to comment.