This commit is contained in:
2026-09-14 00:55:25 +01:00
parent ec43d7b57a
commit e8c0e79bae
17 changed files with 183 additions and 46 deletions
+4 -10
View File
@@ -11,7 +11,7 @@ use chrono::{DateTime, Local, Timelike};
use iced::futures::{channel::mpsc, SinkExt};
use iced::Subscription;
use common::{ClockKind, ClockPayload, Endpoint, Inbox, Wire};
use common::{ClockPayload, Endpoint, Inbox, Wire};
/// Route-key namespace owned by this service; keys are `"clock.<kind>"`.
pub const NAMESPACE: &str = "clock.";
@@ -44,7 +44,7 @@ impl ClockTicker {
tokio::select! {
_ = interval.tick() => {
if let Some(payload) = clock.tick() {
tracing::debug!(key, kind = ?payload.kind, "publishing clock");
tracing::debug!(key, ?payload, "publishing clock");
let wire = Wire::topic(Endpoint::service(key), key, payload);
if sender.send(wire).await.is_err() {
tracing::warn!(key, "clock send failed; stopping service");
@@ -63,16 +63,10 @@ impl ClockTicker {
let value = chrono::Local::now();
let meow = self.last;
if meow.minute() != value.minute() {
return Some(ClockPayload {
kind: ClockKind::Mins,
value: value.format("%H:%M:%S").to_string(),
});
return Some(ClockPayload::Mins(value.format("%H:%M:%S").to_string()));
}
if meow.second() != value.second() {
return Some(ClockPayload {
kind: ClockKind::Seconds,
value: value.format("%H:%M:%S").to_string(),
});
return Some(ClockPayload::Seconds(value.format("%H:%M:%S").to_string()));
}
None
}