@@ -154,22 +154,29 @@ async function sync(githubToken, owner, repo, filterDuplicateSecs, leetcodeCSRFT
154
154
} ;
155
155
console . log ( `Getting submission from LeetCode, offset ${ offset } ` ) ;
156
156
157
- const getSubmissions = async ( retryCount = 0 ) => {
157
+ const getSubmissions = async ( maxRetries , retryCount = 0 ) => {
158
158
try {
159
159
const response = await axios . get ( 'https://leetcode.com/api/submissions/' , config ) ;
160
160
return response ;
161
161
} catch ( exception ) {
162
- if ( retryCount > 3 ) {
162
+ if ( retryCount >= maxRetries ) {
163
+ console . log ( exception ) ;
163
164
throw exception ;
164
165
}
165
- console . log ( 'Error fetching submissions, retrying in ' + 2 ** retryCount + ' seconds...' ) ;
166
+ console . log ( 'Error fetching submissions, retrying in ' + 3 ** retryCount + ' seconds...' ) ;
166
167
// There's a rate limit on LeetCode API, so wait with backoff before retrying.
167
- await delay ( 2 ** retryCount * 1000 ) ;
168
- return getSubmissions ( retryCount + 1 ) ;
168
+ await delay ( 3 ** retryCount * 1000 ) ;
169
+ return getSubmissions ( maxRetries , retryCount + 1 ) ;
169
170
}
170
171
} ;
171
-
172
- response = await getSubmissions ( ) ;
172
+ // On the first attempt, there should be no rate limiting issues, so we fail immediately in case
173
+ // the tokens are configured incorrectly.
174
+ const maxRetries = ( response === null ) ? 0 : 5 ;
175
+ if ( response !== null ) {
176
+ // Add a 1 second delay before all requests after the initial request.
177
+ await delay ( 1000 ) ;
178
+ }
179
+ response = await getSubmissions ( maxRetries ) ;
173
180
if ( ! addToSubmissions ( response , lastTimestamp , filterDuplicateSecs , submissions_dict , submissions ) ) {
174
181
break ;
175
182
}
0 commit comments