Add sync health and explicit sync trigger

This commit is contained in:
Eric Wendland 2026-05-21 19:31:05 +02:00
commit 3c5e95fb87
8 changed files with 1085 additions and 98 deletions

View file

@ -905,6 +905,28 @@ impl Store {
}
}
pub fn list_module_states_with_prefix(
&self,
prefix: &str,
) -> Result<Vec<StoredModuleState>, StoreError> {
let like = format!("{prefix}%");
let mut stmt = self.conn.prepare(
r#"SELECT module, state_json, updated_at_ms
FROM module_state
WHERE module LIKE ?1
ORDER BY module"#,
)?;
let rows = stmt.query_map(params![like], |row| {
Ok(StoredModuleState {
module: row.get(0)?,
state_json: row.get(1)?,
updated_at_ms: row.get(2)?,
})
})?;
rows.collect::<Result<Vec<_>, _>>()
.map_err(StoreError::from)
}
pub fn insert_auth_op(&self, op: &StoredAuthOp) -> Result<(), StoreError> {
self.conn.execute(
r#"INSERT OR REPLACE INTO auth_ops(op_id, resource_id, op_json, created_at_ms)
@ -1672,12 +1694,26 @@ mod tests {
updated_at_ms: 43,
};
store.put_module_state(&state).expect("put state");
store
.put_module_state(&StoredModuleState {
module: "live-sync-status:node:laptop:ssh-certs".to_owned(),
state_json: r#"{"last_attempt_ms":44}"#.to_owned(),
updated_at_ms: 44,
})
.expect("put status state");
assert_eq!(
store
.get_module_state("live-sync:node:laptop:ssh-certs")
.expect("get state"),
Some(state)
);
assert_eq!(
store
.list_module_states_with_prefix("live-sync-status:node:laptop:")
.expect("list prefix")
.len(),
1
);
}
#[test]