|
@ -10,6 +10,8 @@ use rocket_db_pools::Database; |
|
|
use seed::Seed; |
|
|
use seed::Seed; |
|
|
use std::net::SocketAddr; |
|
|
use std::net::SocketAddr; |
|
|
use std::path::PathBuf; |
|
|
use std::path::PathBuf; |
|
|
|
|
|
use std::thread::sleep; |
|
|
|
|
|
use std::time::Duration; |
|
|
use tokio::sync::watch; |
|
|
use tokio::sync::watch; |
|
|
|
|
|
|
|
|
mod db; |
|
|
mod db; |
|
@ -23,6 +25,8 @@ mod taker_inc_message_actor; |
|
|
mod to_sse_event; |
|
|
mod to_sse_event; |
|
|
mod wire; |
|
|
mod wire; |
|
|
|
|
|
|
|
|
|
|
|
const CONNECTION_RETRY_INTERVAL: Duration = Duration::from_secs(5); |
|
|
|
|
|
|
|
|
#[derive(Database)] |
|
|
#[derive(Database)] |
|
|
#[database("taker")] |
|
|
#[database("taker")] |
|
|
pub struct Db(sqlx::SqlitePool); |
|
|
pub struct Db(sqlx::SqlitePool); |
|
@ -88,13 +92,18 @@ async fn main() -> Result<()> { |
|
|
let (order_feed_sender, order_feed_receiver) = watch::channel::<Option<Order>>(None); |
|
|
let (order_feed_sender, order_feed_receiver) = watch::channel::<Option<Order>>(None); |
|
|
let (_balance_feed_sender, balance_feed_receiver) = watch::channel::<Amount>(Amount::ZERO); |
|
|
let (_balance_feed_sender, balance_feed_receiver) = watch::channel::<Amount>(Amount::ZERO); |
|
|
|
|
|
|
|
|
let socket = tokio::net::TcpSocket::new_v4()?; |
|
|
let (read, write) = loop { |
|
|
let connection = socket |
|
|
let socket = tokio::net::TcpSocket::new_v4()?; |
|
|
.connect(opts.taker) |
|
|
if let Ok(connection) = socket.connect(opts.taker).await { |
|
|
.await |
|
|
break connection.into_split(); |
|
|
.expect("Maker should be online first"); |
|
|
} else { |
|
|
|
|
|
println!( |
|
|
let (read, write) = connection.into_split(); |
|
|
"Could not connect to the maker, retrying in {}s ...", |
|
|
|
|
|
CONNECTION_RETRY_INTERVAL.as_secs() |
|
|
|
|
|
); |
|
|
|
|
|
sleep(CONNECTION_RETRY_INTERVAL); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
let figment = rocket::Config::figment() |
|
|
let figment = rocket::Config::figment() |
|
|
.merge(("databases.taker.url", data_dir.join("taker.sqlite"))) |
|
|
.merge(("databases.taker.url", data_dir.join("taker.sqlite"))) |
|
|