add timestamos to dump info

This commit is contained in:
Marin Postma 2021-05-30 15:55:17 +02:00
parent 39c16c0fe4
commit 33c6c4f0ee
No known key found for this signature in database
GPG Key ID: D5241F0C0C865F30
5 changed files with 15 additions and 7 deletions

View File

@ -197,9 +197,10 @@ impl Index {
builder.update_format(format); builder.update_format(format);
builder.index_documents_method(method); builder.index_documents_method(method);
let indexing_callback = //let indexing_callback =
|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step); //|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step);
let indexing_callback = |_, _| ();
let gzipped = false; let gzipped = false;
let addition = match content { let addition = match content {

View File

@ -97,7 +97,9 @@ where
return; return;
} }
let uid = generate_uid(); let uid = generate_uid();
let info = DumpInfo::new(uid.clone(), DumpStatus::InProgress); let info = DumpInfo::new(uid.clone(), DumpStatus::InProgress);
*self.dump_info.write().await = Some(info.clone()); *self.dump_info.write().await = Some(info.clone());
ret.send(Ok(info)).expect("Dump actor is dead"); ret.send(Ok(info)).expect("Dump actor is dead");
@ -126,7 +128,7 @@ where
} }
Err(_) => { Err(_) => {
error!("Dump panicked. Dump status set to failed"); error!("Dump panicked. Dump status set to failed");
*dump_info.write().await = Some(DumpInfo::new(uid, DumpStatus::Failed)); (*dump_info.write().await).as_mut().expect("Inconsistent dump service state").with_error("Unexpected error while performing dump.".to_string());
} }
}; };
} }

View File

@ -1,6 +1,7 @@
use std::fs::File; use std::fs::File;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use chrono::{DateTime, Utc};
use log::{error, info}; use log::{error, info};
#[cfg(test)] #[cfg(test)]
use mockall::automock; use mockall::automock;
@ -86,6 +87,9 @@ pub struct DumpInfo {
pub status: DumpStatus, pub status: DumpStatus,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub error: Option<String>, pub error: Option<String>,
started_at: DateTime<Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
finished_at: Option<DateTime<Utc>>,
} }
impl DumpInfo { impl DumpInfo {
@ -94,15 +98,19 @@ impl DumpInfo {
uid, uid,
status, status,
error: None, error: None,
started_at: Utc::now(),
finished_at: None,
} }
} }
pub fn with_error(&mut self, error: String) { pub fn with_error(&mut self, error: String) {
self.status = DumpStatus::Failed; self.status = DumpStatus::Failed;
self.finished_at = Some(Utc::now());
self.error = Some(error); self.error = Some(error);
} }
pub fn done(&mut self) { pub fn done(&mut self) {
self.finished_at = Some(Utc::now());
self.status = DumpStatus::Done; self.status = DumpStatus::Done;
} }

View File

@ -5,7 +5,6 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use anyhow::Context;
use heed::{EnvOpenOptions, RoTxn}; use heed::{EnvOpenOptions, RoTxn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
@ -84,8 +83,6 @@ impl UpdateStore {
std::fs::copy(src, dst)?; std::fs::copy(src, dst)?;
} }
println!("copied files");
let update_json = UpdateEntry { let update_json = UpdateEntry {
uuid, uuid,
update: update.into(), update: update.into(),

View File

@ -168,7 +168,7 @@ impl UpdateStore {
match res { match res {
Ok(Some(_)) => (), Ok(Some(_)) => (),
Ok(None) => break, Ok(None) => break,
Err(e) => panic!("error while processing update: {}", e), Err(e) => error!("error while processing update: {}", e),
} }
} }
// the ownership on the arc has been taken, we need to exit. // the ownership on the arc has been taken, we need to exit.