From 5e7261d4a66ff5bbe22315cd9fef61cd781a4d82 Mon Sep 17 00:00:00 2001 From: Russell Cousineau Date: Tue, 5 Nov 2019 10:17:50 -0800 Subject: [PATCH] increment upload metric for each successful file --- src/db/file.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/db/file.rs b/src/db/file.rs index 4687f9be1..5959cd3b7 100644 --- a/src/db/file.rs +++ b/src/db/file.rs @@ -153,6 +153,8 @@ pub fn add_path_into_database>(conn: &Connection, use std::collections::HashMap; let mut file_paths_and_mimes: HashMap = HashMap::new(); + use futures::future::Future; + let mut rt = ::tokio::runtime::Runtime::new().unwrap(); let mut to_upload = try!(get_file_list(&path)); @@ -205,6 +207,8 @@ pub fn add_path_into_database>(conn: &Connection, body: Some(content.clone().into()), content_type: Some(mime.clone()), ..Default::default() + }).inspect(|_| { + crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1); })); } else { // If AWS credentials are configured, don't insert/update the database @@ -229,7 +233,6 @@ pub fn add_path_into_database>(conn: &Connection, if rt.block_on(::futures::future::join_all(futures)).is_ok() { // this batch was successful, start another batch if there are still more files - crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(batch_size as i64); batch_size = cmp::min(to_upload.len(), MAX_CONCURRENT_UPLOADS); currently_uploading = to_upload.drain(..batch_size).collect(); attempts = 0; @@ -240,7 +243,6 @@ pub fn add_path_into_database>(conn: &Connection, } } } else { - crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(batch_size as i64); batch_size = cmp::min(to_upload.len(), MAX_CONCURRENT_UPLOADS); currently_uploading = to_upload.drain(..batch_size).collect(); }