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 {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
pub fn parse(s: &str) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"debug" => LogLevel::Debug,
|
||||
"info" => LogLevel::Info,
|
||||
|
|
@ -488,7 +488,7 @@ impl Heartbeat {
|
|||
.unwrap_or(0);
|
||||
|
||||
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)?;
|
||||
|
|
@ -528,8 +528,8 @@ impl CrashDetector {
|
|||
|
||||
pub fn write_state(&self, stats: &RuntimeStats) -> std::io::Result<()> {
|
||||
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();
|
||||
fs::write(&self.state_file, json)
|
||||
}
|
||||
|
|
@ -560,13 +560,21 @@ impl CrashDetector {
|
|||
return false;
|
||||
}
|
||||
|
||||
if let Ok(content) = fs::read_to_string(&self.state_file) {
|
||||
if let Ok(state) = serde_json::from_str::<serde_json::Value>(&content) {
|
||||
if let Some(status) = state.get("status").and_then(|v| v.as_str()) {
|
||||
if status == "stopped" {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(content) = fs::read_to_string(&self.state_file)
|
||||
.and_then(|c| {
|
||||
serde_json::from_str::<serde_json::Value>(&c)
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue