diff --git a/src/main.rs b/src/main.rs index e118d47..5d62209 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ async fn main() -> Result<(), Box> { } }; - info!("parsed object Ok!"); + info!("parsed object Ok!Vec.size={}",parsed_object.len()); info!("object[0]={:?}",parsed_object[0]); let mut word_orm_obj:Vec=vec![]; @@ -44,8 +44,7 @@ async fn main() -> Result<(), Box> { word_entity::add_to_database(word_orm_obj, &db_info.conn) .await - .map_err(|e|{error!("add to database error");error!("{}",e);exit(1)}) - .unwrap(); + .unwrap_or_else(|e: Box|{error!("add to database error");error!("{}",e);exit(1)}); return Ok(()); } diff --git a/src/start_db.rs b/src/start_db.rs index 494bd57..19da66f 100644 --- a/src/start_db.rs +++ b/src/start_db.rs @@ -1,6 +1,6 @@ use log::info; use sea_orm::{ConnectOptions, ConnectionTrait, Database, DatabaseConnection}; -use std::error::Error; +use std::{error::Error, time::Duration}; use sea_orm::Schema; pub struct Starter { @@ -8,7 +8,9 @@ pub struct Starter { } impl Starter { pub async fn connect(db_url:&str) -> Result> { - let opt: ConnectOptions = ConnectOptions::new(db_url); + let mut opt: ConnectOptions = ConnectOptions::new(db_url); + opt.connect_timeout(Duration::from_secs(360)); + let conn_new: DatabaseConnection = Database::connect(opt).await?; Ok(Starter{conn:conn_new})