Skip to content

v2.33.11

Choose a tag to compare

@j-mendez j-mendez released this 14 Mar 13:30
· 1126 commits to main since this release

Whats Changed

Add Website::with_crawl_timeout builder method to add a max timeout for the crawl.
This is useful when robots.txt can change the expected crawl durations.

Example:

use std::time::Duration;
use spider::tokio;
use spider::website::Website;
use tokio::io::AsyncWriteExt;

#[tokio::main]
async fn main() {
    let mut website: Website = Website::new("https://spider.cloud").with_crawl_timeout(Some(Duration::from_millis(10))).build().unwrap();
    let mut rx2: tokio::sync::broadcast::Receiver<spider::page::Page> =
        website.subscribe(0).unwrap();
    let mut stdout = tokio::io::stdout();

    let join_handle = tokio::spawn(async move {
        while let Ok(res) = rx2.recv().await {
            let _ = stdout
                .write_all(format!("- {}\n", res.get_url()).as_bytes())
                .await;
        }
        stdout
    });

    let start = std::time::Instant::now();
    website.crawl().await;
    website.unsubscribe();
    let duration = start.elapsed();
    let mut stdout = join_handle.await.unwrap();

    let _ = stdout
        .write_all(
            format!(
                "Time elapsed in website.crawl() is: {:?} for total pages: {:?}",
                duration,
                website.get_size().await
            )
            .as_bytes(),
        )
        .await;
}

Full Changelog: v2.33.1...v2.33.11