Remove open tickets when sent out
This commit is contained in:
parent
f7c2292833
commit
81686a07ad
2 changed files with 11 additions and 1 deletions
|
|
@ -163,6 +163,15 @@ impl Db {
|
|||
state.open_tickets.values().flatten().cloned().collect()
|
||||
}
|
||||
|
||||
pub(crate) fn remove_open_ticket(&self, road: Road, ticket: Ticket) -> bool {
|
||||
let mut state = self.state.lock().unwrap();
|
||||
if let Some(tickets) = state.open_tickets.get_mut(&road) {
|
||||
tickets.retain(|t| t.plate != ticket.plate);
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub(crate) fn get_plates_by_road(
|
||||
&self,
|
||||
plate: Plate,
|
||||
|
|
|
|||
|
|
@ -88,7 +88,8 @@ pub(crate) async fn send_out_waiting_tickets(db: Db) {
|
|||
debug!(?tickets, "Sending out waiting tickets");
|
||||
for ticket in tickets {
|
||||
if let Some(dispatcher) = db.get_dispatcher_for_road(Road(ticket.road)) {
|
||||
let _ = dispatcher.send(ticket.into()).await;
|
||||
let _ = dispatcher.send(ticket.clone().into()).await;
|
||||
db.remove_open_ticket(Road(ticket.road), ticket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue