feat: add default implementations for initialize, update, finalize in MetaPlugin
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -112,9 +112,8 @@ impl MetaService {
|
||||
}
|
||||
|
||||
for meta_plugin in plugins.iter_mut() {
|
||||
if let Err(e) = meta_plugin.initialize(conn, item_id) {
|
||||
log::warn!("META_SERVICE: Failed to initialize meta plugin: {}", e);
|
||||
}
|
||||
let response = meta_plugin.initialize();
|
||||
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,14 +124,40 @@ impl MetaService {
|
||||
conn: &Connection,
|
||||
) {
|
||||
for meta_plugin in plugins.iter_mut() {
|
||||
meta_plugin.update(chunk, conn);
|
||||
let response = meta_plugin.update(chunk);
|
||||
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finalize_plugins(&self, plugins: &mut [Box<dyn MetaPlugin>], conn: &Connection) {
|
||||
for meta_plugin in plugins.iter_mut() {
|
||||
if let Err(e) = meta_plugin.finalize(conn) {
|
||||
log::warn!("META_SERVICE: Failed to finalize meta plugin: {}", e);
|
||||
let response = meta_plugin.finalize();
|
||||
self.process_plugin_response(conn, item_id, meta_plugin, response);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_plugin_response(
|
||||
&self,
|
||||
conn: &Connection,
|
||||
item_id: i64,
|
||||
plugin: &mut Box<dyn MetaPlugin>,
|
||||
response: crate::meta_plugin::MetaPluginResponse,
|
||||
) {
|
||||
for meta_data in response.metadata {
|
||||
if let Some(processed_meta) = crate::meta_plugin::process_metadata_outputs(
|
||||
&meta_data.name,
|
||||
meta_data.value,
|
||||
plugin.outputs()
|
||||
) {
|
||||
// Save to database
|
||||
let db_meta = crate::db::Meta {
|
||||
id: item_id,
|
||||
name: processed_meta.name,
|
||||
value: processed_meta.value,
|
||||
};
|
||||
if let Err(e) = crate::db::store_meta(conn, db_meta) {
|
||||
log::warn!("META_SERVICE: Failed to store metadata: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user