feat(urgency): 通用紧急度通道(Declarer/Level + 只抬不压折算)+ IoT 首个生产者 + 她自己的结论走结构化标记穿透安静时段
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

This commit is contained in:
AskaEth committed 2026-10-05 13:11:04 +08:00
1 parent 4a2d276881
commit f91a83ff81
14 files changed
+917 -15

No files matched your search

+10 -2
View File
@@ -147,22 +147,30 @@ func (m *Manager) Status(ctx context.Context, deviceID string) (*Device, error)
return nil, fmt.Errorf("iot: status %q: %w", deviceID, ErrDeviceNotFound)
}
// publishUpdate 把 DeviceUpdate 扇出到 bus。发布失败(例如 ctx 被取消)只记日志、
// publishUpdate 把 DeviceUpdate 扇出到 bus。发布的载荷带上本次跃迁的显式严重度:
// 命中安全规则(safetySeverity)的跃迁被标成安全域,其余一律 SeverityRoutine,
// 因此常规设备变化不会被误升级。发布失败(例如 ctx 被取消)只记日志、
// 不作为错误返回:设备状态已经改变,不应因为某个观察者没收到事件就把本次控制判为
// 失败。
func (m *Manager) publishUpdate(ctx context.Context, provider string, d Device, action string, params map[string]any) {
severity, safety := safetySeverity(d.Type, action)
msg := fmt.Sprintf("设备 %s · %s(%s)", d.Name, action, provider)
if safety {
msg = fmt.Sprintf("%s · 安全域 %s", msg, severity.String())
}
if err := m.bus.Publish(ctx, DeviceUpdateSubject, DeviceUpdate{
Provider: provider,
Device: d,
Action: action,
Params: params,
Message: msg,
Severity: severity,
}); err != nil {
m.log.Error("iot publish device update", "device", d.ID, "action", action, "error", err)
return
}
m.log.Debug("iot device update published", "device", d.ID, "action", action, "provider", provider)
m.log.Debug("iot device update published",
"device", d.ID, "action", action, "provider", provider, "severity", severity.String())
}
// discardLogger 在 log 非 nil 时原样返回,否则返回一个不写任何输出的 logger,