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,7 +485,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(T) => match tx2_changed {
Ok(T) => {
let mut tradefee_vec_temp: Vec<TradeFee> = Vec::new();
let result = request_others::request_trade_fee(
let mut result;
loop {
result = request_others::request_trade_fee(
API_KEY,
SECRET_KEY,
local_epoch,
@ -495,6 +497,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
)
.await;
if tradefee_vec_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result {
Ok(T) => {
tx_tradefee_vec.send_modify(|vec| *vec = tradefee_vec_temp);
@ -880,11 +889,22 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.unwrap();
loop {
let mut exchange_info_data_temp: Vec<ExchangeInfo> = Vec::new();
let result = coin_health_check_team::request_others::request_exchange_infomation(
let mut result;
loop {
result = coin_health_check_team::request_others::request_exchange_infomation(
&client,
&mut exchange_info_data_temp,
)
.await;
// retry
if exchange_info_data_temp.len() == 0 {
sleep(Duration::from_secs(3)).await;
} else {
break;
}
}
match result {
Ok(T) => {
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.");
}
Err(E) => {
eprintln!("Couldn't execute strategists.");
}
}
// sleep as much as the loop recurs per 1 second if all operation finished within 1 second.
elapsed_time = instant.elapsed().as_millis();
println!("elapsed time: {}", elapsed_time);
if 250 > elapsed_time {
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)
.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