use options to schedule snapshot

This commit is contained in:
mpostma 2021-03-17 12:01:56 +01:00
parent ee838be41b
commit c966b1dd94
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
3 changed files with 21 additions and 14 deletions

View File

@ -60,9 +60,7 @@ impl Data {
let path = options.db_path.clone();
create_dir_all(&path)?;
let index_size = options.max_mdb_size.get_bytes() as usize;
let update_store_size = options.max_udb_size.get_bytes() as usize;
let index_controller = IndexController::new(&path, index_size, update_store_size)?;
let index_controller = IndexController::new(&path, &options)?;
let mut api_keys = ApiKeys {
master: options.clone().master_key,

View File

@ -20,6 +20,7 @@ use tokio::time::sleep;
use crate::index::{Document, SearchQuery, SearchResult};
use crate::index::{Facets, Settings, UpdateResult};
use crate::option::Opt;
pub use updates::{Failed, Processed, Processing};
use snapshot::SnapshotService;
@ -64,20 +65,28 @@ pub struct IndexController {
impl IndexController {
pub fn new(
path: impl AsRef<Path>,
index_size: usize,
update_store_size: usize,
options: &Opt,
) -> anyhow::Result<Self> {
let index_size = options.max_mdb_size.get_bytes() as usize;
let update_store_size = options.max_udb_size.get_bytes() as usize;
let uuid_resolver = uuid_resolver::UuidResolverHandle::new(&path)?;
let index_handle = index_actor::IndexActorHandle::new(&path, index_size)?;
let update_handle =
update_actor::UpdateActorHandle::new(index_handle.clone(), &path, update_store_size)?;
let snapshot_service = SnapshotService::new(
index_handle.clone(),
uuid_resolver.clone(),
update_handle.clone(),
Duration::from_millis(10000),
"/dev/toto".into());
tokio::task::spawn(snapshot_service.run());
if options.schedule_snapshot {
let snapshot_service = SnapshotService::new(
index_handle.clone(),
uuid_resolver.clone(),
update_handle.clone(),
Duration::from_secs(options.snapshot_interval_sec),
options.snapshot_dir.clone()
);
tokio::task::spawn(snapshot_service.run());
}
Ok(Self {
uuid_resolver,
index_handle,

View File

@ -191,8 +191,8 @@ pub struct Opt {
pub schedule_snapshot: bool,
/// Defines time interval, in seconds, between each snapshot creation.
#[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC")]
pub snapshot_interval_sec: Option<u64>,
#[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC", default_value = "86400")] // 24h
pub snapshot_interval_sec: u64,
/// Folder where dumps are created when the dump route is called.
#[structopt(long, env = "MEILI_DUMPS_DIR", default_value = "dumps/")]