Repository navigation
Library events and spawn
audit_stream starts the audit and gives you a futures::Stream of AuditEvents. Use it to drive a progress bar or a live log.
use futures::StreamExt;
use sitevet::{AuditEvent, Options, audit_stream};
let mut stream = audit_stream("https://example.com", Options::default());
while let Some(event) = stream.next().await {
match event {
AuditEvent::PageFetched { index, url, status, .. } => println!("{index:>3} {status} {url}"),
AuditEvent::CrawlComplete { pages, checks_total, .. } => println!("{pages} pages, {checks_total} checks"),
AuditEvent::PageComplete { index, pages_total, score, .. } => println!("{index}/{pages_total} scored {score}"),
AuditEvent::AuditComplete { report, .. } => println!("done: {}", report.score),
_ => {}
}
}Like audit, it needs a tokio context. Dropping the stream cancels the audit. stream.cancel() does the same while you keep the stream, and stream.final_report().await waits for the report and drops events you have not read.
AuditStart { url, max_pages }-
PageFetched { url, status, depth, index, ms }, one per page as the crawl finds it -
PageRendered { url, ok, index, pages }, one per page the browser or PageSpeed Insights finished, thenRenderComplete { provider, rendered, pages, ms }. Only when rendering ran. -
CrawlComplete { pages, checks_total, ms }. From here on, counts run against a known total. -
CheckComplete { url, rule_id, status, checks_done, checks_total }andPageComplete { url, index, pages_total, score, findings, metrics, ms }as pages finish -
AuditComplete { score, pages, checks, ms, report }, with the same reportauditwould return
AuditEvent is #[non_exhaustive]: keep a _ => {} arm, since later versions add variants. Events serialise to JSON with a "type" field ("page_fetched" and so on), so you can forward them to a web UI as they are.
The event channel is bounded. A slow reader slows the audit down instead of growing memory.
spawn runs the audit on a runtime sitevet owns, so it works from any executor: GPUI, smol, futures::executor or a plain thread.
use futures::executor::block_on;
use sitevet::{AuditEvent, Options, spawn};
let handle = spawn("https://example.com", Options::default());
let events = handle.events(); // an async_channel::Receiver<AuditEvent>; clone it freely
std::thread::spawn(move || {
block_on(async {
while let Ok(event) = events.recv().await {
if let AuditEvent::PageFetched { url, .. } = event {
eprintln!("fetched {url}");
}
}
})
});
let report = block_on(handle.report())?;handle.cancel() stops network work at once, and report() then returns Error::Cancelled. Dropping the handle cancels too. The runtime starts on first use with options.runtime_threads workers (default 2) and shuts down when the last handle is gone.
A full example is in examples/spawn-futures.rs:
cargo run -p sitevet --example spawn-futures -- https://example.comsitevet is MIT licensed. Source, issues and releases: github.com/Abdulkader-Safi/sitevet.
Getting started
CLI
Library
Reference