Skip to content

Instantly share code, notes, and snippets.

@skeptrunedev
Created September 4, 2024 18:48
Show Gist options
  • Save skeptrunedev/e7cc428766a6152bbb860424c34a7f67 to your computer and use it in GitHub Desktop.
Save skeptrunedev/e7cc428766a6152bbb860424c34a7f67 to your computer and use it in GitHub Desktop.
Tokio Timeout Code for scraper Html::parse_element function
pub async fn timeout_safe_convert_html_to_text(html: &str) -> String {
match tokio::time::timeout(std::time::Duration::from_secs(1), async {
convert_html_to_text(html)
})
.await
{
Ok(text) => text,
Err(_e) => {
log::error!("Error converting this html to text in 1s: {:?}", html);
sentry::capture_message(
&format!("Error converting html to text in 1s: {:?}", html),
sentry::Level::Error,
);
html.to_string()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment