Send out stale tickets
This commit is contained in:
parent
351e301293
commit
a831821026
3 changed files with 18 additions and 2 deletions
|
|
@ -155,6 +155,11 @@ impl Db {
|
||||||
.push(ticket);
|
.push(ticket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_open_tickets(&self) -> Vec<Ticket> {
|
||||||
|
let state = self.state.lock().unwrap();
|
||||||
|
state.open_tickets.values().flatten().cloned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_plates_by_road(
|
pub(crate) fn get_plates_by_road(
|
||||||
&self,
|
&self,
|
||||||
plate: Plate,
|
plate: Plate,
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
db::{Camera, CameraId, Db, DbHolder, DispatcherId, Limit, Mile, Plate, Road, Timestamp},
|
db::{Camera, CameraId, Db, DbHolder, DispatcherId, Limit, Mile, Plate, Road, Timestamp},
|
||||||
frame::{ClientFrames, ServerFrames},
|
frame::{ClientFrames, ServerFrames},
|
||||||
heartbeat::Heartbeat,
|
heartbeat::Heartbeat,
|
||||||
ticketing::issue_possible_ticket,
|
ticketing::{issue_possible_ticket, send_out_waiting_tickets},
|
||||||
Connection, Shutdown,
|
Connection, Shutdown,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -240,6 +240,7 @@ impl Handler {
|
||||||
roads.to_vec(),
|
roads.to_vec(),
|
||||||
send_message.clone(),
|
send_message.clone(),
|
||||||
);
|
);
|
||||||
|
send_out_waiting_tickets(db).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::db::{CameraId, Db, Plate, Ticket};
|
use crate::db::{CameraId, Db, Plate, Road, Ticket};
|
||||||
|
|
||||||
pub(crate) async fn issue_possible_ticket(db: &mut Db, plate: Plate, camera_id: CameraId) {
|
pub(crate) async fn issue_possible_ticket(db: &mut Db, plate: Plate, camera_id: CameraId) {
|
||||||
let camera = db.get_camera(camera_id).unwrap();
|
let camera = db.get_camera(camera_id).unwrap();
|
||||||
|
|
@ -60,3 +60,13 @@ pub(crate) async fn issue_possible_ticket(db: &mut Db, plate: Plate, camera_id:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) async fn send_out_waiting_tickets(db: Db) {
|
||||||
|
let tickets = db.get_open_tickets();
|
||||||
|
|
||||||
|
for ticket in tickets {
|
||||||
|
if let Some(dispatcher) = db.get_dispatcher_for_road(Road(ticket.road)) {
|
||||||
|
let _ = dispatcher.send(ticket.into()).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue