(typ: &str, dev_eui: &str, b: &[u8])
| 15 | |
| 16 | #[allow(clippy::enum_variant_names)] |
| 17 | pub async fn log_event_for_device(typ: &str, dev_eui: &str, b: &[u8]) -> Result<()> { |
| 18 | let conf = config::get(); |
| 19 | |
| 20 | // per device stream |
| 21 | if conf.monitoring.per_device_event_log_max_history > 0 { |
| 22 | let key = redis_key(format!("device:{{{}}}:stream:event", dev_eui)); |
| 23 | () = redis::pipe() |
| 24 | .atomic() |
| 25 | .cmd("XADD") |
| 26 | .arg(&key) |
| 27 | .arg("MAXLEN") |
| 28 | .arg("~") |
| 29 | .arg(conf.monitoring.per_device_event_log_max_history) |
| 30 | .arg("*") |
| 31 | .arg(typ) |
| 32 | .arg(b) |
| 33 | .ignore() |
| 34 | .cmd("PEXPIRE") |
| 35 | .arg(&key) |
| 36 | .arg(conf.monitoring.per_device_event_log_ttl.as_millis() as usize) |
| 37 | .ignore() |
| 38 | .query_async(&mut get_async_redis_conn().await?) |
| 39 | .await?; |
| 40 | } |
| 41 | |
| 42 | // global device stream |
| 43 | if conf.monitoring.device_event_log_max_history > 0 { |
| 44 | let key = redis_key("device:stream:event".to_string()); |
| 45 | () = redis::cmd("XADD") |
| 46 | .arg(&key) |
| 47 | .arg("MAXLEN") |
| 48 | .arg("~") |
| 49 | .arg(conf.monitoring.device_event_log_max_history) |
| 50 | .arg("*") |
| 51 | .arg(typ) |
| 52 | .arg(b) |
| 53 | .query_async(&mut get_async_redis_conn().await?) |
| 54 | .await?; |
| 55 | } |
| 56 | |
| 57 | Ok(()) |
| 58 | } |
| 59 | |
| 60 | pub async fn get_event_logs( |
| 61 | key: String, |
no test coverage detected