Skip to content

Commit c00a7f6

Browse files
authored
Merge pull request #469 from miller-time/fix-upload-metric-inc
increment upload metric for each successful file
2 parents a400e45 + 5e7261d commit c00a7f6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/db/file.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
153153
use std::collections::HashMap;
154154
let mut file_paths_and_mimes: HashMap<PathBuf, String> = HashMap::new();
155155

156+
use futures::future::Future;
157+
156158
let mut rt = ::tokio::runtime::Runtime::new().unwrap();
157159

158160
let mut to_upload = try!(get_file_list(&path));
@@ -205,6 +207,8 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
205207
body: Some(content.clone().into()),
206208
content_type: Some(mime.clone()),
207209
..Default::default()
210+
}).inspect(|_| {
211+
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1);
208212
}));
209213
} else {
210214
// If AWS credentials are configured, don't insert/update the database
@@ -229,7 +233,6 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
229233

230234
if rt.block_on(::futures::future::join_all(futures)).is_ok() {
231235
// this batch was successful, start another batch if there are still more files
232-
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(batch_size as i64);
233236
batch_size = cmp::min(to_upload.len(), MAX_CONCURRENT_UPLOADS);
234237
currently_uploading = to_upload.drain(..batch_size).collect();
235238
attempts = 0;
@@ -240,7 +243,6 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
240243
}
241244
}
242245
} else {
243-
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(batch_size as i64);
244246
batch_size = cmp::min(to_upload.len(), MAX_CONCURRENT_UPLOADS);
245247
currently_uploading = to_upload.drain(..batch_size).collect();
246248
}

0 commit comments

Comments
 (0)