From f94f6a35f4270729b1a0d4d45decea56c6ab4bd8 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sun, 21 Feb 2021 00:30:28 -0500 Subject: [PATCH] Remove panic, monitor video hashing duration. --- fuzzysearch/src/handlers.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fuzzysearch/src/handlers.rs b/fuzzysearch/src/handlers.rs index 7fd2bb6..7b52b8a 100644 --- a/fuzzysearch/src/handlers.rs +++ b/fuzzysearch/src/handlers.rs @@ -16,6 +16,11 @@ lazy_static! { "Duration to perform an image hash operation" ) .unwrap(); + static ref VIDEO_HASH_DURATION: Histogram = register_histogram!( + "fuzzysearch_api_video_hash_seconds", + "Duration to perform a video hash operation" + ) + .unwrap(); static ref IMAGE_URL_DOWNLOAD_DURATION: Histogram = register_histogram!( "fuzzysearch_api_image_url_download_seconds", "Duration to download an image from a provided URL" @@ -130,23 +135,25 @@ async fn hash_input(form: warp::multipart::FormData) -> (i64, img_hash::ImageHas } #[tracing::instrument(skip(form))] -async fn hash_video(form: warp::multipart::FormData) -> Vec<[u8; 8]> { +async fn hash_video(form: warp::multipart::FormData) -> Option> { use bytes::Buf; let bytes = get_field_bytes(form, "video").await; + let _timer = VIDEO_HASH_DURATION.start_timer(); let hashes = tokio::task::spawn_blocking(move || { if infer::is_video(&bytes) { - fuzzysearch_common::video::extract_video_hashes(bytes.reader()).unwrap() + fuzzysearch_common::video::extract_video_hashes(bytes.reader()).ok() } else if infer::image::is_gif(&bytes) { - fuzzysearch_common::video::extract_gif_hashes(bytes.reader()).unwrap() + fuzzysearch_common::video::extract_gif_hashes(bytes.reader()).ok() } else { - panic!("invalid file type provided"); + None } }) .instrument(span!(tracing::Level::TRACE, "hashing video")) .await .unwrap(); + drop(_timer); hashes }