Exclude offline gateways from multicast scheduling.

This commit is contained in:
Orne Brocaar 2024-04-15 14:09:38 +01:00
parent 378b314a32
commit 2889da37c2
2 changed files with 13 additions and 4 deletions

View File

@ -601,13 +601,16 @@ pub async fn get_schedulable_queue_items(limit: usize) -> Result<Vec<MulticastGr
where where
id in ( id in (
select select
id qi.id
from from
multicast_group_queue_item multicast_group_queue_item qi
inner join gateway g
on g.gateway_id = qi.gateway_id
where where
scheduler_run_after <= $2 qi.scheduler_run_after <= $2
and now() - make_interval(secs => g.stats_interval_secs * 2) <= g.last_seen_at
order by order by
created_at qi.created_at
limit $1 limit $1
) )
returning * returning *
@ -919,6 +922,8 @@ pub mod test {
gateway_id: EUI64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]), gateway_id: EUI64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]),
name: "test-gw".into(), name: "test-gw".into(),
tenant_id: t.id, tenant_id: t.id,
stats_interval_secs: 30,
last_seen_at: Some(Utc::now()),
..Default::default() ..Default::default()
}) })
.await .await

View File

@ -1,3 +1,5 @@
use chrono::Utc;
use super::assert; use super::assert;
use crate::storage::{ use crate::storage::{
application, device, device_gateway, device_profile, fields, gateway, multicast, tenant, application, device, device_gateway, device_profile, fields, gateway, multicast, tenant,
@ -37,6 +39,8 @@ async fn test_multicast() {
.cloned() .cloned()
.collect(), .collect(),
), ),
stats_interval_secs: 30,
last_seen_at: Some(Utc::now()),
..Default::default() ..Default::default()
}) })
.await .await