Add retry code

This commit is contained in:
Sik Yoon 2023-10-04 20:08:21 +09:00
parent 0100c36191
commit 13f1e59e7a

View File

@ -485,16 +485,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(T) => match tx2_changed { Ok(T) => match tx2_changed {
Ok(T) => { Ok(T) => {
let mut tradefee_vec_temp: Vec<TradeFee> = Vec::new(); let mut tradefee_vec_temp: Vec<TradeFee> = Vec::new();
let result = request_others::request_trade_fee( let mut result;
API_KEY, loop {
SECRET_KEY, result = request_others::request_trade_fee(
local_epoch, API_KEY,
difference_epoch, SECRET_KEY,
&client, local_epoch,
&mut tradefee_vec_temp, difference_epoch,
) &client,
.await; &mut tradefee_vec_temp,
)
.await;
if tradefee_vec_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result { match result {
Ok(T) => { Ok(T) => {
tx_tradefee_vec.send_modify(|vec| *vec = tradefee_vec_temp); tx_tradefee_vec.send_modify(|vec| *vec = tradefee_vec_temp);
@ -880,11 +889,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap(); .unwrap();
loop { loop {
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new(); let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
let result = coin_health_check_team::request_others::request_exchange_infomation( let mut result;
&client, loop {
&mut exchange_info_data_temp, result = coin_health_check_team::request_others::request_exchange_infomation(
) &client,
.await; &mut exchange_info_data_temp,
)
.await;
// retry
if exchange_info_data_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result { match result {
Ok(T) => { Ok(T) => {
tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp); tx_exchange_info_data.send_modify(|vec| *vec = exchange_info_data_temp);
@ -997,12 +1017,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.expect("The mpsc channel has been closed."); .expect("The mpsc channel has been closed.");
} }
Err(E) => { Err(E) => {
eprintln!("Couldn't execute strategists.");
} }
} }
// sleep as much as the loop recurs per 1 second if all operation finished within 1 second. // sleep as much as the loop recurs per 1 second if all operation finished within 1 second.
elapsed_time = instant.elapsed().as_millis(); elapsed_time = instant.elapsed().as_millis();
println!("elapsed time: {}", elapsed_time);
if 250 > elapsed_time { if 250 > elapsed_time {
sleep(Duration::from_millis((250 - elapsed_time) as u64)).await; sleep(Duration::from_millis((250 - elapsed_time) as u64)).await;
} }
@ -1093,7 +1113,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.send(20) .send(20)
.expect("The mpsc channel has been closed."); .expect("The mpsc channel has been closed.");
} }
Err(E) => {} Err(E) => {
eprint!("Error: {:?}", E);
}
} }
// sleep as much as the loop recurs per 200ms second if all operation finished within 200ms // sleep as much as the loop recurs per 200ms second if all operation finished within 200ms