pscand-core: improve crash detection with stopped status check
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Icd4c2f29c321df38fc22a98d8110fa836a6a6964
This commit is contained in:
parent
f4961c7f95
commit
2fe05c6466
1 changed files with 19 additions and 11 deletions
|
|
@ -27,7 +27,7 @@ pub enum LogLevel {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LogLevel {
|
impl LogLevel {
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn parse(s: &str) -> Self {
|
||||||
match s.to_lowercase().as_str() {
|
match s.to_lowercase().as_str() {
|
||||||
"debug" => LogLevel::Debug,
|
"debug" => LogLevel::Debug,
|
||||||
"info" => LogLevel::Info,
|
"info" => LogLevel::Info,
|
||||||
|
|
@ -488,7 +488,7 @@ impl Heartbeat {
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
if let Some(parent) = self.path.parent() {
|
if let Some(parent) = self.path.parent() {
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut file = fs::File::create(&self.path)?;
|
let mut file = fs::File::create(&self.path)?;
|
||||||
|
|
@ -528,8 +528,8 @@ impl CrashDetector {
|
||||||
|
|
||||||
pub fn write_state(&self, stats: &RuntimeStats) -> std::io::Result<()> {
|
pub fn write_state(&self, stats: &RuntimeStats) -> std::io::Result<()> {
|
||||||
if let Some(parent) = self.state_file.parent() {
|
if let Some(parent) = self.state_file.parent() {
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?
|
||||||
}
|
};
|
||||||
let json = serde_json::to_string_pretty(stats).unwrap_or_default();
|
let json = serde_json::to_string_pretty(stats).unwrap_or_default();
|
||||||
fs::write(&self.state_file, json)
|
fs::write(&self.state_file, json)
|
||||||
}
|
}
|
||||||
|
|
@ -560,15 +560,23 @@ impl CrashDetector {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(content) = fs::read_to_string(&self.state_file) {
|
if let Some(content) = fs::read_to_string(&self.state_file)
|
||||||
if let Ok(state) = serde_json::from_str::<serde_json::Value>(&content) {
|
.and_then(|c| {
|
||||||
if let Some(status) = state.get("status").and_then(|v| v.as_str()) {
|
serde_json::from_str::<serde_json::Value>(&c)
|
||||||
if status == "stopped" {
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))
|
||||||
|
})
|
||||||
|
.ok()
|
||||||
|
.and_then(|state| {
|
||||||
|
state
|
||||||
|
.get("status")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
})
|
||||||
|
{
|
||||||
|
if content == "stopped" {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue