master
Bel LaPointe 2025-11-20 14:29:01 -07:00
parent 56d0628ece
commit 72eb29d766
1 changed files with 31 additions and 2 deletions

View File

@ -234,7 +234,7 @@ impl File {
let now = Delta::now_time();
if let Some(due) = before.next_due(now.clone()) {
if due >= now {
self.append(Delta::add_at(before.clone(), due))?;
self.append(Delta::add_at(before.clone(), now))?;
}
}
}
@ -589,12 +589,14 @@ struct Delta {
ts: u64,
op: Op,
task: Task,
tasks: Option<Vec<Task>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
enum Op {
Add,
Remove,
Snapshot,
}
impl Delta {
@ -603,6 +605,7 @@ impl Delta {
ts: ts,
op: op,
task: task,
tasks: None,
}
}
@ -842,7 +845,7 @@ impl Events {
fn snapshot(&self) -> Result<Vec<Task>, String> {
let mut result = vec![];
for event in self.0.iter() {
match event.op {
match &event.op {
Op::Add => match event.task.next_due(event.ts) {
Some(next_due) => match next_due <= Delta::now_time() {
true => result.push(event.task.clone()),
@ -863,6 +866,7 @@ impl Events {
}
}
}
Op::Snapshot => result = event.tasks.clone().unwrap(),
};
}
Ok(result)
@ -873,6 +877,31 @@ impl Events {
mod test_events {
use super::*;
#[test]
fn test_events_op_snapshot() {
tests::with_dir(|d| {
tests::write_file(&d, "plain", "- who cares");
tests::write_file(
&d,
".plain.some_host",
r#"
{"ts":1, "op":"Snapshot", "task":"", "tasks":["snapshotted"]}
"#,
);
let events =
Events::new(&d.path().join("plain").to_str().unwrap().to_string()).unwrap();
assert_eq!(1, events.0.len(), "events: {:?}", events);
let snapshot = events.snapshot().unwrap();
assert_eq!(1, snapshot.len());
assert_eq!(
serde_yaml::Value::String("snapshotted".to_string()),
snapshot[0].0
);
});
}
#[test]
fn test_events_oplog_to_snapshot_one() {
tests::with_dir(|d| {