Prevent race conditions

- This is a massive cope, I don't know how to code

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2024-01-17 17:16:37 +00:00
parent 36ee6030ce
commit 7200447bc5
23 changed files with 510 additions and 311 deletions

View File

@@ -5,15 +5,18 @@ mod config;
mod data;
mod database;
mod routes;
mod state;
mod types;
mod utils;
use crate::utils::cleanup;
use config::Config;
use dotenv::dotenv;
use log4rs::config::Deserializers;
use state::BroadcastMessage;
use std::error::Error;
use tokio::{spawn, sync::broadcast};
use types::{BroadcastMessage, Class};
use types::Class;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
@@ -22,21 +25,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
let app_config = Config::arc_from_env();
let mut threads = Vec::new();
let (broadcast_sender, _) = broadcast::channel::<BroadcastMessage>(100);
cleanup(&app_config.clickhouse_client).await;
let (broadcast_bus, _) = broadcast::channel::<BroadcastMessage>(100);
threads.push(spawn(data::market::run(
app_config.clone(),
Class::UsEquity,
broadcast_sender.clone(),
broadcast_bus.clone(),
)));
threads.push(spawn(data::market::run(
app_config.clone(),
Class::Crypto,
broadcast_sender.clone(),
broadcast_bus.clone(),
)));
threads.push(spawn(routes::run(app_config.clone(), broadcast_sender)));
threads.push(spawn(routes::run(app_config.clone(), broadcast_bus)));
for thread in threads {
thread.await?;