From 2584bf8a55ef7fe5df3ab4bc580cef234e51a80a Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Thu, 18 Aug 2022 23:35:24 +0000 Subject: [PATCH] bug fixed --- src/schedulers/balance/scheduler.rs | 102 +++++++++++++--------------- src/schedulers/game/scheduler.rs | 101 +++++++++++++-------------- src/schedulers/member/scheduler.rs | 64 +++++++---------- 3 files changed, 116 insertions(+), 151 deletions(-) diff --git a/src/schedulers/balance/scheduler.rs b/src/schedulers/balance/scheduler.rs index 89653ae..0072619 100644 --- a/src/schedulers/balance/scheduler.rs +++ b/src/schedulers/balance/scheduler.rs @@ -64,33 +64,6 @@ impl Scheduler { Ok(()) } - async fn add_history( - &'static self, - item: String, - start_at: i64, - code: i64, - message: Option, - ) -> Result<(), Box> { - let conn = self.pool.get().expect("conn"); - let complete_at = (chrono::Utc::now()).timestamp(); - - self - .synchronization_history_repository - .insert( - &conn, - &repositories::synchronization_history::models::NewSynchronizationHistory { - item, - start_at, - complete_at, - code, - message, - }, - ) - .expect("synchronization_history insert"); - - Ok(()) - } - async fn balance_for_user(&'static self) -> Result<(), Box> { let j_synchronization = Job::new_async("0 0 0/1 * * *", move |_uuid, _l| { Box::pin(async move { @@ -122,28 +95,38 @@ impl Scheduler { } self - .add_history( - repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), - start_at, - 0, - None, + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: 0, + message: None, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); Ok::<(), api::core::models::Error>(()) } .await { + let conn = self.pool.get().expect("conn"); + self - .add_history( - repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), - start_at, - e.code, - e.msg.clone(), + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: e.code, + message: e.msg, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); } }) })?; @@ -197,28 +180,37 @@ impl Scheduler { } self - .add_history( - repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), - start_at, - 0, - None, + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_BALANCE_PARTNER.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: 0, + message: None, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); Ok::<(), api::core::models::Error>(()) } .await { + let conn = self.pool.get().expect("conn"); self - .add_history( - repositories::synchronization::models::ITEM_BALANCE_USER.to_string(), - start_at, - e.code, - e.msg.clone(), + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_BALANCE_PARTNER.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: e.code, + message: e.msg, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); } }) })?; diff --git a/src/schedulers/game/scheduler.rs b/src/schedulers/game/scheduler.rs index bd56bde..6d22df0 100644 --- a/src/schedulers/game/scheduler.rs +++ b/src/schedulers/game/scheduler.rs @@ -63,33 +63,6 @@ impl Scheduler { Ok(()) } - async fn add_history( - &'static self, - item: String, - start_at: i64, - code: i64, - message: Option, - ) -> Result<(), Box> { - let complete_at = (chrono::Utc::now()).timestamp(); - let conn = self.pool.get().expect("conn"); - - self - .synchronization_history_repository - .insert( - &conn, - &repositories::synchronization_history::models::NewSynchronizationHistory { - item, - start_at, - complete_at, - code, - message, - }, - ) - .expect("synchronization_history insert"); - - Ok(()) - } - async fn list_vendors(&'static self) -> Result<(), Box> { let j_synchronization = Job::new_async("0 0 0/1 * * *", move |_uuid, _l| { Box::pin(async move { @@ -124,14 +97,18 @@ impl Scheduler { .expect("vendor upsert"); self - .add_history( - repositories::synchronization::models::ITEM_VENDORS.to_string(), - start_at, - 0, - None, + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_VENDORS.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: 0, + message: None, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); self.list_games().await; @@ -139,15 +116,20 @@ impl Scheduler { } .await { + let conn = self.pool.get().expect("conn"); self - .add_history( - repositories::synchronization::models::ITEM_VENDORS.to_string(), - start_at, - e.code, - e.msg.clone(), + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_VENDORS.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: e.code, + message: e.msg, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); } }) })?; @@ -203,28 +185,37 @@ impl Scheduler { .expect("game upsert"); self - .add_history( - repositories::synchronization::models::ITEM_GAMES.to_string(), - start_at, - 0, - None, + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_GAMES.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: 0, + message: None, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); Ok::<(), api::core::models::Error>(()) } .await { + let conn = self.pool.get().expect("conn"); self - .add_history( - repositories::synchronization::models::ITEM_GAMES.to_string(), - start_at, - e.code, - e.msg.clone(), + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_GAMES.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: e.code, + message: e.msg, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); } } } diff --git a/src/schedulers/member/scheduler.rs b/src/schedulers/member/scheduler.rs index 9ed8e1c..c4265e6 100644 --- a/src/schedulers/member/scheduler.rs +++ b/src/schedulers/member/scheduler.rs @@ -59,33 +59,6 @@ impl Scheduler { Ok(()) } - async fn add_history( - &'static self, - item: String, - start_at: i64, - code: i64, - message: Option, - ) -> Result<(), Box> { - let conn = self.pool.get().expect("conn"); - let complete_at = (chrono::Utc::now()).timestamp(); - - self - .synchronization_history_repository - .insert( - &conn, - &repositories::synchronization_history::models::NewSynchronizationHistory { - item, - start_at, - complete_at, - code, - message, - }, - ) - .expect("synchronization_history insert"); - - Ok(()) - } - async fn list_members(&'static self) -> Result<(), Box> { let j_synchronization = Job::new_async("0 0 0/1 * * *", move |_uuid, _l| { Box::pin(async move { @@ -111,28 +84,37 @@ impl Scheduler { } self - .add_history( - repositories::synchronization::models::ITEM_MEMBERS.to_string(), - start_at, - 0, - None, + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_MEMBERS.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: 0, + message: None, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); Ok::<(), api::core::models::Error>(()) } .await { + let conn = self.pool.get().expect("conn"); self - .add_history( - repositories::synchronization::models::ITEM_MEMBERS.to_string(), - start_at, - e.code, - e.msg.clone(), + .synchronization_history_repository + .insert( + &conn, + &repositories::synchronization_history::models::NewSynchronizationHistory { + item: repositories::synchronization::models::ITEM_MEMBERS.to_string(), + start_at, + complete_at: (chrono::Utc::now()).timestamp(), + code: e.code, + message: e.msg, + }, ) - .await - .expect("add_history"); + .expect("synchronization_history insert"); } }) })?;