refactor: move DB to agentcore (#228)
- add db_path to settings for all agents - refactor updater poll_and_handle_update to use a mutex guard - add db() method to optics agent traitbuddies-main-deployment
parent
be4704e85a
commit
1174800624
@ -1,12 +1,21 @@ |
||||
use color_eyre::eyre::{Result, WrapErr}; |
||||
use rocksdb::{Options, DB}; |
||||
use std::path::Path; |
||||
|
||||
/// Shared functionality surrounding use of rocksdb
|
||||
pub mod persistence; |
||||
pub use persistence::UsingPersistence; |
||||
|
||||
use rocksdb::{Options, DB}; |
||||
pub use persistence::UsingPersistence; |
||||
|
||||
/// Opens db at `db_path` and creates if missing
|
||||
pub fn from_path(db_path: String) -> DB { |
||||
pub fn from_path(db_path: &str) -> Result<DB> { |
||||
let path = Path::new(db_path).canonicalize()?; |
||||
|
||||
let mut opts = Options::default(); |
||||
opts.create_if_missing(true); |
||||
DB::open(&opts, db_path).expect("Failed to open db path") |
||||
|
||||
Ok(DB::open(&opts, &path).wrap_err(format!( |
||||
"Failed to open db path {}, canonicalized as {:?}", |
||||
db_path, path |
||||
))?) |
||||
} |
||||
|
Loading…
Reference in new issue