feat: add finalization tracking to meta plugins
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -6,6 +6,7 @@ use crate::meta_plugin::MetaPlugin;
|
|||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct DigestSha256MetaPlugin {
|
pub struct DigestSha256MetaPlugin {
|
||||||
hasher: Sha256,
|
hasher: Sha256,
|
||||||
|
is_finalized: bool,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
options: std::collections::HashMap<String, serde_yaml::Value>,
|
options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
@@ -38,6 +39,7 @@ impl DigestSha256MetaPlugin {
|
|||||||
|
|
||||||
DigestSha256MetaPlugin {
|
DigestSha256MetaPlugin {
|
||||||
hasher: Sha256::new(),
|
hasher: Sha256::new(),
|
||||||
|
is_finalized: false,
|
||||||
meta_name: "digest_sha256".to_string(),
|
meta_name: "digest_sha256".to_string(),
|
||||||
outputs: final_outputs,
|
outputs: final_outputs,
|
||||||
options: final_options,
|
options: final_options,
|
||||||
@@ -50,6 +52,14 @@ impl DigestSha256MetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaPlugin for DigestSha256MetaPlugin {
|
impl MetaPlugin for DigestSha256MetaPlugin {
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
self.is_finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_finalized(&mut self, finalized: bool) {
|
||||||
|
self.is_finalized = finalized;
|
||||||
|
}
|
||||||
|
|
||||||
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn initialize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata: Vec::new(),
|
metadata: Vec::new(),
|
||||||
@@ -58,6 +68,14 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process again
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
// Finalize the hash
|
// Finalize the hash
|
||||||
@@ -73,6 +91,9 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
metadata.push(meta_data);
|
metadata.push(meta_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
|
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
is_finalized: true,
|
is_finalized: true,
|
||||||
@@ -80,6 +101,14 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process more data
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
self.hasher.update(data);
|
self.hasher.update(data);
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata: Vec::new(),
|
metadata: Vec::new(),
|
||||||
@@ -120,6 +149,7 @@ impl MetaPlugin for DigestSha256MetaPlugin {
|
|||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct ReadTimeMetaPlugin {
|
pub struct ReadTimeMetaPlugin {
|
||||||
start_time: Option<Instant>,
|
start_time: Option<Instant>,
|
||||||
|
is_finalized: bool,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
options: std::collections::HashMap<String, serde_yaml::Value>,
|
options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
@@ -152,6 +182,7 @@ impl ReadTimeMetaPlugin {
|
|||||||
|
|
||||||
ReadTimeMetaPlugin {
|
ReadTimeMetaPlugin {
|
||||||
start_time: None,
|
start_time: None,
|
||||||
|
is_finalized: false,
|
||||||
meta_name: "read_time".to_string(),
|
meta_name: "read_time".to_string(),
|
||||||
outputs: final_outputs,
|
outputs: final_outputs,
|
||||||
options: final_options,
|
options: final_options,
|
||||||
@@ -164,7 +195,23 @@ impl ReadTimeMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaPlugin for ReadTimeMetaPlugin {
|
impl MetaPlugin for ReadTimeMetaPlugin {
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
self.is_finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_finalized(&mut self, finalized: bool) {
|
||||||
|
self.is_finalized = finalized;
|
||||||
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process again
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
if let Some(start_time) = self.start_time {
|
if let Some(start_time) = self.start_time {
|
||||||
@@ -181,6 +228,9 @@ impl MetaPlugin for ReadTimeMetaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
|
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
is_finalized: true,
|
is_finalized: true,
|
||||||
@@ -188,6 +238,14 @@ impl MetaPlugin for ReadTimeMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
fn update(&mut self, _data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process more data
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if self.start_time.is_none() {
|
if self.start_time.is_none() {
|
||||||
self.start_time = Some(Instant::now());
|
self.start_time = Some(Instant::now());
|
||||||
}
|
}
|
||||||
@@ -230,6 +288,7 @@ impl MetaPlugin for ReadTimeMetaPlugin {
|
|||||||
pub struct ReadRateMetaPlugin {
|
pub struct ReadRateMetaPlugin {
|
||||||
start_time: Option<Instant>,
|
start_time: Option<Instant>,
|
||||||
bytes_read: u64,
|
bytes_read: u64,
|
||||||
|
is_finalized: bool,
|
||||||
meta_name: String,
|
meta_name: String,
|
||||||
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
options: std::collections::HashMap<String, serde_yaml::Value>,
|
options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||||
@@ -263,6 +322,7 @@ impl ReadRateMetaPlugin {
|
|||||||
ReadRateMetaPlugin {
|
ReadRateMetaPlugin {
|
||||||
start_time: None,
|
start_time: None,
|
||||||
bytes_read: 0,
|
bytes_read: 0,
|
||||||
|
is_finalized: false,
|
||||||
meta_name: "read_rate".to_string(),
|
meta_name: "read_rate".to_string(),
|
||||||
outputs: final_outputs,
|
outputs: final_outputs,
|
||||||
options: final_options,
|
options: final_options,
|
||||||
@@ -275,7 +335,23 @@ impl ReadRateMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MetaPlugin for ReadRateMetaPlugin {
|
impl MetaPlugin for ReadRateMetaPlugin {
|
||||||
|
fn is_finalized(&self) -> bool {
|
||||||
|
self.is_finalized
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_finalized(&mut self, finalized: bool) {
|
||||||
|
self.is_finalized = finalized;
|
||||||
|
}
|
||||||
|
|
||||||
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
fn finalize(&mut self) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process again
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let mut metadata = Vec::new();
|
let mut metadata = Vec::new();
|
||||||
|
|
||||||
if let Some(start_time) = self.start_time {
|
if let Some(start_time) = self.start_time {
|
||||||
@@ -296,6 +372,9 @@ impl MetaPlugin for ReadRateMetaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark as finalized
|
||||||
|
self.is_finalized = true;
|
||||||
|
|
||||||
crate::meta_plugin::MetaPluginResponse {
|
crate::meta_plugin::MetaPluginResponse {
|
||||||
metadata,
|
metadata,
|
||||||
is_finalized: true,
|
is_finalized: true,
|
||||||
@@ -303,6 +382,14 @@ impl MetaPlugin for ReadRateMetaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
fn update(&mut self, data: &[u8]) -> crate::meta_plugin::MetaPluginResponse {
|
||||||
|
// If already finalized, don't process more data
|
||||||
|
if self.is_finalized {
|
||||||
|
return crate::meta_plugin::MetaPluginResponse {
|
||||||
|
metadata: Vec::new(),
|
||||||
|
is_finalized: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if self.start_time.is_none() {
|
if self.start_time.is_none() {
|
||||||
self.start_time = Some(Instant::now());
|
self.start_time = Some(Instant::now());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user