Clean up
This commit is contained in:
parent
c4828d691f
commit
fc03309af2
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use troll_patrol::{
|
use troll_patrol::{
|
||||||
extra_info::ExtraInfo,
|
extra_info::ExtraInfo,
|
||||||
get_date, increment_simulated_date,
|
increment_simulated_date,
|
||||||
simulation::{
|
simulation::{
|
||||||
bridge::Bridge,
|
bridge::Bridge,
|
||||||
censor::{Censor, Hides::*, Speed::*, Totality::*},
|
censor::{Censor, Hides::*, Speed::*, Totality::*},
|
||||||
|
@ -120,10 +120,8 @@ pub async fn main() {
|
||||||
let mut tp = 0;
|
let mut tp = 0;
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
for _ in 0..config.num_days {
|
for day in 1..=config.num_days {
|
||||||
let la_net = HyperNet {
|
println!("Starting day {} of the simulation", day);
|
||||||
hostname: format!("http://localhost:{}", config.la_port),
|
|
||||||
};
|
|
||||||
|
|
||||||
// USER TASKS
|
// USER TASKS
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ use serde_json::json;
|
||||||
use std::{collections::HashSet, convert::Infallible, net::SocketAddr, time::Duration};
|
use std::{collections::HashSet, convert::Infallible, net::SocketAddr, time::Duration};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
spawn,
|
spawn,
|
||||||
sync::{broadcast, mpsc, oneshot},
|
sync::{mpsc, oneshot},
|
||||||
time::sleep,
|
time::sleep,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,12 +44,8 @@ async fn serve_extra_infos(
|
||||||
pub async fn server() {
|
pub async fn server() {
|
||||||
let (context_tx, context_rx) = mpsc::channel(32);
|
let (context_tx, context_rx) = mpsc::channel(32);
|
||||||
let request_tx = context_tx.clone();
|
let request_tx = context_tx.clone();
|
||||||
let shutdown_cmd_tx = context_tx.clone();
|
|
||||||
let (shutdown_tx, mut shutdown_rx) = broadcast::channel(16);
|
|
||||||
let kill_context = shutdown_tx.subscribe();
|
|
||||||
|
|
||||||
let context_manager =
|
spawn(async move { create_context_manager(context_rx).await });
|
||||||
spawn(async move { create_context_manager(context_rx, kill_context).await });
|
|
||||||
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 8004));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 8004));
|
||||||
let make_svc = make_service_fn(move |_conn: &AddrStream| {
|
let make_svc = make_service_fn(move |_conn: &AddrStream| {
|
||||||
|
@ -75,13 +71,9 @@ pub async fn server() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_context_manager(
|
async fn create_context_manager(context_rx: mpsc::Receiver<Command>) {
|
||||||
context_rx: mpsc::Receiver<Command>,
|
|
||||||
mut kill: broadcast::Receiver<()>,
|
|
||||||
) {
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
create_context = context_manager(context_rx) => create_context,
|
create_context = context_manager(context_rx) => create_context,
|
||||||
_ = kill.recv() => {println!("Shut down context_manager");},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +90,6 @@ async fn context_manager(mut context_rx: mpsc::Receiver<Command>) {
|
||||||
}
|
}
|
||||||
sleep(Duration::from_millis(1)).await;
|
sleep(Duration::from_millis(1)).await;
|
||||||
}
|
}
|
||||||
Shutdown { shutdown_sig } => {
|
|
||||||
drop(shutdown_sig);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,9 +100,6 @@ enum Command {
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
sender: oneshot::Sender<Result<Response<Body>, Infallible>>,
|
sender: oneshot::Sender<Result<Response<Body>, Infallible>>,
|
||||||
},
|
},
|
||||||
Shutdown {
|
|
||||||
shutdown_sig: broadcast::Sender<()>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_extra_infos(extra_infos_pages: &mut Vec<String>, request: Bytes) -> Response<Body> {
|
fn add_extra_infos(extra_infos_pages: &mut Vec<String>, request: Bytes) -> Response<Body> {
|
||||||
|
|
Loading…
Reference in New Issue