mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-25 14:53:34 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5677e5e955 | ||
|
|
91e0c2ee62 |
@@ -326,6 +326,24 @@ impl Database for LibSqlBackend {
|
||||
libsql_migrations::run_incremental(&conn).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn shutdown(&self) -> Result<(), DatabaseError> {
|
||||
match self.db.flush_replicator().await {
|
||||
Ok(Some(frame_no)) => {
|
||||
tracing::debug!("libSQL replicator flushed at frame {}", frame_no);
|
||||
Ok(())
|
||||
}
|
||||
Ok(None) => {
|
||||
tracing::debug!("No libSQL replicator to flush, skipping shutdown sync");
|
||||
Ok(())
|
||||
}
|
||||
Err(libsql::Error::SyncNotSupported(_)) => {
|
||||
tracing::debug!("libSQL sync not supported, skipping flush on shutdown");
|
||||
Ok(())
|
||||
}
|
||||
Err(error) => Err(DatabaseError::from(error)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== Row conversion helpers ====================
|
||||
|
||||
@@ -523,6 +523,13 @@ pub trait Database:
|
||||
{
|
||||
/// Run schema migrations for this backend.
|
||||
async fn run_migrations(&self) -> Result<(), DatabaseError>;
|
||||
|
||||
/// Shutdown hook for backend-specific drain/flush behavior.
|
||||
///
|
||||
/// Default implementation is a no-op so existing backends remain compatible.
|
||||
async fn shutdown(&self) -> Result<(), DatabaseError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -61,6 +61,11 @@ impl Database for PgBackend {
|
||||
async fn run_migrations(&self) -> Result<(), DatabaseError> {
|
||||
self.store.run_migrations().await
|
||||
}
|
||||
|
||||
async fn shutdown(&self) -> Result<(), DatabaseError> {
|
||||
self.store.pool().close();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== ConversationStore ====================
|
||||
|
||||
@@ -672,6 +672,8 @@ async fn async_main() -> anyhow::Result<()> {
|
||||
.as_ref()
|
||||
.map(|db| Arc::clone(db) as Arc<dyn ironclaw::db::SettingsStore>);
|
||||
|
||||
let db_for_shutdown = components.db.clone();
|
||||
|
||||
let deps = AgentDeps {
|
||||
store: components.db,
|
||||
llm: components.llm,
|
||||
@@ -930,6 +932,12 @@ async fn async_main() -> anyhow::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(db) = db_for_shutdown {
|
||||
if let Err(e) = db.shutdown().await {
|
||||
tracing::warn!("Failed to shutdown database cleanly: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
tracing::debug!("Agent shutdown complete");
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user