Support add_snapshots on cli
This commit is contained in:
2
.changelogs/2021-10-11-issue23-client.md
Normal file
2
.changelogs/2021-10-11-issue23-client.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- The `avoid_snapshots` configuration value, if set, will cause the replica to
|
||||||
|
avoid creating snapshots unless required.
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
|
use crate::settings::Settings;
|
||||||
use taskchampion::{server::Server, Replica};
|
use taskchampion::{server::Server, Replica};
|
||||||
use termcolor::WriteColor;
|
use termcolor::WriteColor;
|
||||||
|
|
||||||
pub(crate) fn execute<W: WriteColor>(
|
pub(crate) fn execute<W: WriteColor>(
|
||||||
w: &mut W,
|
w: &mut W,
|
||||||
replica: &mut Replica,
|
replica: &mut Replica,
|
||||||
|
settings: &Settings,
|
||||||
server: &mut Box<dyn Server>,
|
server: &mut Box<dyn Server>,
|
||||||
) -> Result<(), crate::Error> {
|
) -> Result<(), crate::Error> {
|
||||||
// TODO: configurable avoid_snapshots
|
replica.sync(server, settings.avoid_snapshots)?;
|
||||||
replica.sync(server, false)?;
|
|
||||||
writeln!(w, "sync complete.")?;
|
writeln!(w, "sync complete.")?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -25,9 +26,10 @@ mod test {
|
|||||||
let mut replica = test_replica();
|
let mut replica = test_replica();
|
||||||
let server_dir = TempDir::new().unwrap();
|
let server_dir = TempDir::new().unwrap();
|
||||||
let mut server = test_server(&server_dir);
|
let mut server = test_server(&server_dir);
|
||||||
|
let settings = Settings::default();
|
||||||
|
|
||||||
// Note that the details of the actual sync are tested thoroughly in the taskchampion crate
|
// Note that the details of the actual sync are tested thoroughly in the taskchampion crate
|
||||||
execute(&mut w, &mut replica, &mut server).unwrap();
|
execute(&mut w, &mut replica, &settings, &mut server).unwrap();
|
||||||
assert_eq!(&w.into_string(), "sync complete.\n")
|
assert_eq!(&w.into_string(), "sync complete.\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ pub(crate) fn invoke(command: Command, settings: Settings) -> Result<(), crate::
|
|||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut server = get_server(&settings)?;
|
let mut server = get_server(&settings)?;
|
||||||
return cmd::sync::execute(&mut w, &mut replica, &mut server);
|
return cmd::sync::execute(&mut w, &mut replica, &settings, &mut server);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handled in the first match, but here to ensure this match is exhaustive
|
// handled in the first match, but here to ensure this match is exhaustive
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub(crate) struct Settings {
|
|||||||
|
|
||||||
/// replica
|
/// replica
|
||||||
pub(crate) data_dir: PathBuf,
|
pub(crate) data_dir: PathBuf,
|
||||||
|
pub(crate) avoid_snapshots: bool,
|
||||||
|
|
||||||
/// remote sync server
|
/// remote sync server
|
||||||
pub(crate) server_client_key: Option<String>,
|
pub(crate) server_client_key: Option<String>,
|
||||||
@@ -91,6 +92,7 @@ impl Settings {
|
|||||||
let table_keys = [
|
let table_keys = [
|
||||||
"data_dir",
|
"data_dir",
|
||||||
"modification_count_prompt",
|
"modification_count_prompt",
|
||||||
|
"avoid_snapshots",
|
||||||
"server_client_key",
|
"server_client_key",
|
||||||
"server_origin",
|
"server_origin",
|
||||||
"encryption_secret",
|
"encryption_secret",
|
||||||
@@ -124,6 +126,20 @@ impl Settings {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_bool_cfg<F: FnOnce(bool)>(
|
||||||
|
table: &Table,
|
||||||
|
name: &'static str,
|
||||||
|
setter: F,
|
||||||
|
) -> Result<()> {
|
||||||
|
if let Some(v) = table.get(name) {
|
||||||
|
setter(
|
||||||
|
v.as_bool()
|
||||||
|
.ok_or_else(|| anyhow!(".{}: not a boolean value", name))?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
get_str_cfg(table, "data_dir", |v| {
|
get_str_cfg(table, "data_dir", |v| {
|
||||||
self.data_dir = v.into();
|
self.data_dir = v.into();
|
||||||
})?;
|
})?;
|
||||||
@@ -132,6 +148,10 @@ impl Settings {
|
|||||||
self.modification_count_prompt = Some(v);
|
self.modification_count_prompt = Some(v);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
get_bool_cfg(table, "avoid_snapshots", |v| {
|
||||||
|
self.avoid_snapshots = v;
|
||||||
|
})?;
|
||||||
|
|
||||||
get_str_cfg(table, "server_client_key", |v| {
|
get_str_cfg(table, "server_client_key", |v| {
|
||||||
self.server_client_key = Some(v);
|
self.server_client_key = Some(v);
|
||||||
})?;
|
})?;
|
||||||
@@ -313,6 +333,7 @@ impl Default for Settings {
|
|||||||
filename: None,
|
filename: None,
|
||||||
data_dir,
|
data_dir,
|
||||||
modification_count_prompt: None,
|
modification_count_prompt: None,
|
||||||
|
avoid_snapshots: false,
|
||||||
server_client_key: None,
|
server_client_key: None,
|
||||||
server_origin: None,
|
server_origin: None,
|
||||||
encryption_secret: None,
|
encryption_secret: None,
|
||||||
|
|||||||
@@ -46,6 +46,12 @@ If using a remote server:
|
|||||||
* `server_client_key` - Client key to identify this replica to the sync server (a UUID)
|
* `server_client_key` - Client key to identify this replica to the sync server (a UUID)
|
||||||
If not set, then sync is done to a local server.
|
If not set, then sync is done to a local server.
|
||||||
|
|
||||||
|
## Snapshots
|
||||||
|
|
||||||
|
* `avoid_snapshots` - If running on a CPU-, memory-, or bandwidth-constrained
|
||||||
|
device, set this to true. The effect is that this replica will wait longer
|
||||||
|
to produce a snapshot, in the hopes that other replicas will do so first.
|
||||||
|
|
||||||
## Reports
|
## Reports
|
||||||
|
|
||||||
* `reports` - a mapping of each report's name to its definition.
|
* `reports` - a mapping of each report's name to its definition.
|
||||||
|
|||||||
Reference in New Issue
Block a user