hive-sh4re: split inbox, container, journal, and schedule wire shapes into their own modules
Closes the #3110 split — lib.rs is now just the crate doc comment and the pub mod list. journal.rs's new doc comment fixes a pre-existing bug: the old JournalPriority doc text in lib.rs was actually half Capability's doc (a leftover from an earlier reorder that moved the code but not the comment above it).
This commit is contained in:
parent
b785f96d30
commit
80f16094f1
30 changed files with 513 additions and 486 deletions
|
|
@ -1,6 +1,6 @@
|
|||
//! Delivery half of the harness-local reminders store. Polls [`Reminders`]
|
||||
//! for due rows and pushes each as a
|
||||
//! [`hive_sh4re::DeliveredMessage`] down an mpsc channel the serve loop
|
||||
//! [`hive_sh4re::inbox::DeliveredMessage`] down an mpsc channel the serve loop
|
||||
//! races against the broker long-poll — mirrors `todo_server`'s `Notify`
|
||||
//! wake, but a reminder fire carries real per-row data (message/id), so a
|
||||
//! bare `Notify` doesn't fit; the channel carries the finished message
|
||||
|
|
@ -60,7 +60,7 @@ fn remind_max_pending() -> u64 {
|
|||
/// select), while cleanly disabling delivery.
|
||||
pub async fn run(
|
||||
store: Option<Arc<Reminders>>,
|
||||
tx: mpsc::UnboundedSender<hive_sh4re::DeliveredMessage>,
|
||||
tx: mpsc::UnboundedSender<hive_sh4re::inbox::DeliveredMessage>,
|
||||
) {
|
||||
let Some(store) = store else {
|
||||
tracing::error!("reminders db unavailable — reminder delivery disabled");
|
||||
|
|
@ -73,7 +73,7 @@ pub async fn run(
|
|||
}
|
||||
}
|
||||
|
||||
fn tick(store: &Reminders, tx: &mpsc::UnboundedSender<hive_sh4re::DeliveredMessage>) {
|
||||
fn tick(store: &Reminders, tx: &mpsc::UnboundedSender<hive_sh4re::inbox::DeliveredMessage>) {
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
let due = match store.due(now, REMINDER_BATCH_LIMIT) {
|
||||
Ok(rows) => rows,
|
||||
|
|
@ -84,7 +84,7 @@ fn tick(store: &Reminders, tx: &mpsc::UnboundedSender<hive_sh4re::DeliveredMessa
|
|||
};
|
||||
for r in due {
|
||||
let body = prepare_body(&r.message, r.file_path.as_deref());
|
||||
let dm = hive_sh4re::DeliveredMessage {
|
||||
let dm = hive_sh4re::inbox::DeliveredMessage {
|
||||
from: "reminder".into(),
|
||||
body,
|
||||
id: 0,
|
||||
|
|
@ -109,7 +109,7 @@ fn tick(store: &Reminders, tx: &mpsc::UnboundedSender<hive_sh4re::DeliveredMessa
|
|||
pub fn store(
|
||||
store: &Reminders,
|
||||
message: &str,
|
||||
timing: &hive_sh4re::ReminderTiming,
|
||||
timing: &hive_sh4re::inbox::ReminderTiming,
|
||||
file_path: Option<&str>,
|
||||
) -> Result<i64, String> {
|
||||
let max = remind_max_pending();
|
||||
|
|
@ -237,8 +237,8 @@ fn write_payload(path: &Path, message: &str) -> Result<(), String> {
|
|||
}
|
||||
|
||||
/// Resolve the `due_at` unix timestamp for a `StoreReminder` request.
|
||||
fn resolve_due_at(timing: &hive_sh4re::ReminderTiming) -> anyhow::Result<i64> {
|
||||
use hive_sh4re::ReminderTiming;
|
||||
fn resolve_due_at(timing: &hive_sh4re::inbox::ReminderTiming) -> anyhow::Result<i64> {
|
||||
use hive_sh4re::inbox::ReminderTiming;
|
||||
match timing {
|
||||
ReminderTiming::InSeconds { seconds } => {
|
||||
let now = std::time::SystemTime::now();
|
||||
|
|
@ -268,14 +268,15 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn resolve_due_at_in_seconds_is_close_to_now_plus_n() {
|
||||
let due = resolve_due_at(&hive_sh4re::ReminderTiming::InSeconds { seconds: 60 }).unwrap();
|
||||
let due =
|
||||
resolve_due_at(&hive_sh4re::inbox::ReminderTiming::InSeconds { seconds: 60 }).unwrap();
|
||||
let now = chrono::Utc::now().timestamp();
|
||||
assert!((due - now - 60).abs() <= 2, "due={due} now={now}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolve_due_at_at_passes_through() {
|
||||
let due = resolve_due_at(&hive_sh4re::ReminderTiming::At {
|
||||
let due = resolve_due_at(&hive_sh4re::inbox::ReminderTiming::At {
|
||||
unix_timestamp: 123_456,
|
||||
})
|
||||
.unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue