#![feature(proc_macro_hygiene, decl_macro)] // Macros #[macro_use] extern crate rocket; #[macro_use] extern crate lazy_static; extern crate pretty_env_logger; #[macro_use] extern crate log; // External crates use rocket::{Build, Rocket}; use sea_orm_rocket::rocket::fairing::{self, AdHoc}; use sea_orm_rocket::Database; // Local crates use migration::MigratorTrait; mod amf; mod cors; mod db; mod env; mod logger; mod model; mod repo; mod route; mod task; use crate::task::run_tasks; // Module imports use crate::db::Db; use env::Config; lazy_static! { /// Contains variables defind in .env file static ref CONFIG: Config = Config::new(); } async fn run_migrations(rocket: Rocket) -> fairing::Result { let conn = &Db::fetch(&rocket).unwrap().conn; let _ = migration::Migrator::up(conn, None).await; Ok(rocket) } async fn start_rocket() -> Result<(), sea_orm_rocket::rocket::Error> { rocket::build() .attach(Db::init()) .attach(AdHoc::try_on_ignite("Migrations", run_migrations)) .attach(crate::cors::Cors) .mount( "/v1", routes![ route::company::get_all, route::company::get_by_isin, route::transaction::get_by_company_id, route::transaction::get_all, route::in_process_transaction::get_all, route::in_process_transaction::retry_failed_transaction, route::in_process_transaction::retry_all ], ) .launch() .await .map(|_| ()) } #[rocket::main] pub async fn main() -> Result<(), Box> { logger::init_log()?; // Run tasks tokio::task::spawn(async { run_tasks().await }); let result = start_rocket().await; info!("Rocket: deorbit."); if let Some(err) = result.err() { println!("Error: {}", err); } Ok(()) }