It returns the device queue-item and a bool indicating if there are more items in the queue.
(dev_eui: &EUI64)
| 113 | |
| 114 | /// It returns the device queue-item and a bool indicating if there are more items in the queue. |
| 115 | pub async fn get_next_for_dev_eui(dev_eui: &EUI64) -> Result<(DeviceQueueItem, bool), Error> { |
| 116 | let items: Vec<DeviceQueueItem> = device_queue_item::dsl::device_queue_item |
| 117 | .filter(device_queue_item::dev_eui.eq(&dev_eui)) |
| 118 | .order_by(device_queue_item::created_at) |
| 119 | .limit(2) |
| 120 | .load(&mut get_async_db_conn().await?) |
| 121 | .await |
| 122 | .map_err(|e| Error::from_diesel(e, dev_eui.to_string()))?; |
| 123 | |
| 124 | // Return NotFound on empty Vec. |
| 125 | if items.is_empty() { |
| 126 | return Err(Error::NotFound(dev_eui.to_string())); |
| 127 | } |
| 128 | |
| 129 | // In case the transmission is pending and hasn't timed-out yet, do not |
| 130 | // return it. |
| 131 | if items[0].is_pending |
| 132 | && let Some(timeout_after) = &items[0].timeout_after |
| 133 | && timeout_after > &Utc::now() |
| 134 | { |
| 135 | return Err(Error::NotFound(dev_eui.to_string())); |
| 136 | } |
| 137 | |
| 138 | // Return first item and bool indicating if there are more items in the queue. |
| 139 | Ok((items[0].clone(), items.len() > 1)) |
| 140 | } |
| 141 | |
| 142 | pub async fn get_for_dev_eui(dev_eui: &EUI64) -> Result<Vec<DeviceQueueItem>, Error> { |
| 143 | let items = device_queue_item::dsl::device_queue_item |