huskies: merge 743
This commit is contained in:
@@ -162,10 +162,46 @@ pub fn write_node_presence(node_id: &str, address: &str, last_seen: f64, alive:
|
||||
node.address.advance_seq(floor);
|
||||
node.last_seen.advance_seq(floor);
|
||||
node.alive.advance_seq(floor);
|
||||
node.label.advance_seq(floor);
|
||||
node.assigned_project.advance_seq(floor);
|
||||
node.last_seen_ms.advance_seq(floor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Write agent metadata fields for an existing node presence entry.
|
||||
///
|
||||
/// Updates `label`, `assigned_project`, and `last_seen_ms` for the node
|
||||
/// identified by `node_id`. Does nothing if the node does not exist or the
|
||||
/// CRDT is not initialised.
|
||||
pub fn write_node_metadata(
|
||||
node_id: &str,
|
||||
label: &str,
|
||||
assigned_project: Option<&str>,
|
||||
last_seen_ms: f64,
|
||||
) {
|
||||
let Some(state_mutex) = get_crdt() else {
|
||||
return;
|
||||
};
|
||||
let Ok(mut state) = state_mutex.lock() else {
|
||||
return;
|
||||
};
|
||||
let Some(&idx) = state.node_index.get(node_id) else {
|
||||
return;
|
||||
};
|
||||
apply_and_persist(&mut state, |s| {
|
||||
s.crdt.doc.nodes[idx].label.set(label.to_string())
|
||||
});
|
||||
apply_and_persist(&mut state, |s| {
|
||||
s.crdt.doc.nodes[idx]
|
||||
.assigned_project
|
||||
.set(assigned_project.unwrap_or("").to_string())
|
||||
});
|
||||
apply_and_persist(&mut state, |s| {
|
||||
s.crdt.doc.nodes[idx].last_seen_ms.set(last_seen_ms)
|
||||
});
|
||||
}
|
||||
|
||||
/// Read all node presence entries from the CRDT document.
|
||||
///
|
||||
/// Returns `None` before `init()`.
|
||||
@@ -200,10 +236,25 @@ fn extract_node_view(node: &NodePresenceCrdt) -> Option<NodePresenceView> {
|
||||
JsonValue::Bool(b) => b,
|
||||
_ => true,
|
||||
};
|
||||
let label = match node.label.view() {
|
||||
JsonValue::String(s) if !s.is_empty() => Some(s),
|
||||
_ => None,
|
||||
};
|
||||
let assigned_project = match node.assigned_project.view() {
|
||||
JsonValue::String(s) if !s.is_empty() => Some(s),
|
||||
_ => None,
|
||||
};
|
||||
let last_seen_ms = match node.last_seen_ms.view() {
|
||||
JsonValue::Number(n) if n > 0.0 => Some(n),
|
||||
_ => None,
|
||||
};
|
||||
Some(NodePresenceView {
|
||||
node_id,
|
||||
address,
|
||||
last_seen,
|
||||
alive,
|
||||
label,
|
||||
assigned_project,
|
||||
last_seen_ms,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user