Factor replica and sync configuration into simple owned structs

This commit is contained in:
Dustin J. Mitchell
2020-11-28 16:57:32 -05:00
parent 87596bb1f0
commit 8af7ba286d
16 changed files with 81 additions and 23 deletions

View File

@@ -1,8 +1,9 @@
use crate::config::ReplicaConfig;
use crate::errors::Error;
use crate::server::Server;
use crate::task::{Status, Task};
use crate::taskdb::TaskDB;
use crate::taskstorage::{Operation, TaskMap, TaskStorage};
use crate::taskstorage::{KVStorage, Operation, TaskMap, TaskStorage};
use chrono::Utc;
use failure::Fallible;
use std::collections::HashMap;
@@ -21,6 +22,11 @@ impl Replica {
}
}
pub fn from_config(config: ReplicaConfig) -> Fallible<Replica> {
let storage = Box::new(KVStorage::new(config.taskdb_dir)?);
Ok(Replica::new(storage))
}
#[cfg(test)]
pub fn new_inmemory() -> Replica {
Replica::new(Box::new(crate::taskstorage::InMemoryStorage::new()))
@@ -140,7 +146,7 @@ impl Replica {
}
/// Synchronize this replica against the given server.
pub fn sync(&mut self, server: &mut dyn Server) -> Fallible<()> {
pub fn sync(&mut self, server: &mut Box<dyn Server>) -> Fallible<()> {
self.taskdb.sync(server)
}