Created
September 4, 2024 18:48
-
-
Save skeptrunedev/e7cc428766a6152bbb860424c34a7f67 to your computer and use it in GitHub Desktop.
Tokio Timeout Code for scraper Html::parse_element function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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