Skip to content

Commit 42693b0

Browse files
committed
retry both errors in both places. works on testnet
1 parent 0feab05 commit 42693b0

File tree

2 files changed

+48
-17
lines changed

2 files changed

+48
-17
lines changed

src/backend_task/contested_names/query_dpns_contested_resources.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ impl AppContext {
3939
order_ascending: true,
4040
};
4141

42-
// Initialize retry counter and start time
42+
// Initialize retry counter
4343
let mut retries = 0;
44-
let start_time = Instant::now();
4544

4645
let contested_resources = match ContestedResource::fetch_many(&sdk, query.clone()).await
4746
{
@@ -96,14 +95,14 @@ impl AppContext {
9695
return Err(e);
9796
}
9897
}
99-
if e.to_string().contains("try another server") {
98+
if e.to_string().contains("try another server")
99+
|| e.to_string().contains(
100+
"contract not found when querying from value with contract info",
101+
)
102+
{
100103
retries += 1;
101104
if retries > MAX_RETRIES {
102-
tracing::error!(
103-
"Max retries reached for query after {:?}: {}",
104-
start_time.elapsed(),
105-
e
106-
);
105+
tracing::error!("Max retries reached for query: {}", e);
107106
return Err(format!(
108107
"Error fetching contested resources after retries: {}",
109108
e

src/backend_task/contested_names/query_dpns_vote_contenders.rs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,47 @@ impl AppContext {
4444
result_type: ContestedDocumentVotePollDriveQueryResultType::DocumentsAndVoteTally,
4545
};
4646

47-
let contenders =
48-
ContenderWithSerializedDocument::fetch_many(&sdk, contenders_query.clone())
49-
.await
50-
.map_err(|e| {
47+
// Define retries
48+
const MAX_RETRIES: usize = 3;
49+
let mut retries = 0;
50+
51+
loop {
52+
match ContenderWithSerializedDocument::fetch_many(&sdk, contenders_query.clone()).await
53+
{
54+
Ok(contenders) => {
55+
// If successful, proceed to insert/update contenders
56+
return self
57+
.db
58+
.insert_or_update_contenders(name, &contenders, document_type, self)
59+
.map_err(|e| e.to_string());
60+
}
61+
Err(e) => {
5162
tracing::error!("Error fetching contested resources: {}", e);
52-
format!("Error fetching contested resources: {}", e)
53-
})?;
54-
self.db
55-
.insert_or_update_contenders(name, &contenders, document_type, self)
56-
.map_err(|e| e.to_string())
63+
let error_str = e.to_string();
64+
if error_str.contains("try another server")
65+
|| error_str.contains(
66+
"contract not found when querying from value with contract info",
67+
)
68+
{
69+
retries += 1;
70+
if retries > MAX_RETRIES {
71+
tracing::error!(
72+
"Max retries reached for query_dpns_vote_contenders: {}",
73+
e
74+
);
75+
return Err(format!(
76+
"Error fetching contested resources after retries: {}",
77+
e
78+
));
79+
} else {
80+
continue;
81+
}
82+
} else {
83+
// For other errors, return immediately
84+
return Err(format!("Error fetching contested resources: {}", e));
85+
}
86+
}
87+
}
88+
}
5789
}
5890
}

0 commit comments

Comments
 (0)