Skip to content

Commit

Permalink
Retry when api fails
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Wang <jay@zijie.wang>
  • Loading branch information
xiaohk committed Jul 12, 2024
1 parent ef7ba0c commit c7150c0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
26 changes: 9 additions & 17 deletions src/components/author-list/author-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,20 @@ export class RecRecAuthorList extends LitElement {
//==========================================================================||
// Private Helpers ||
//==========================================================================||
async updateAuthorDetails() {
async updateAuthorDetails(retry = 3) {
if (this.authors.length === 0) {
this.authorDetails = [];
return;
}

let done = false;
let retry = 3;

while (!done && retry > 0) {
try {
const data = await searchAuthorDetails(
this.authors.map(d => d.authorId)
);
this.authorDetails = data;
done = true;
} catch (e) {
await new Promise<void>(resolve => {
setTimeout(resolve, 2000);
});
retry -= 1;
}
try {
const data = await searchAuthorDetails(this.authors.map(d => d.authorId));
this.authorDetails = data;
} catch (e) {
await new Promise<void>(resolve => {
setTimeout(resolve, 2000);
});
await this.updateAuthorDetails(retry - 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/author-view/author-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class RecRecAuthorView extends LitElement {
//==========================================================================||
// Event Handlers ||
//==========================================================================||
searchInput(e: InputEvent, delay = 200) {
searchInput(e: InputEvent, delay = 600) {
const target = e.currentTarget as HTMLInputElement;
const query = target.value;

Expand Down
20 changes: 16 additions & 4 deletions src/components/recommender-view/recommender-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,22 @@ export class RecRecRecommenderView extends LitElement {
return awardMap;
}

async updateCitations() {
console.time('Query citations');
const paperCitations = await getPaperCitations([...this.selectedPaperIDs]);
console.timeEnd('Query citations');
async updateCitations(retry = 3) {
let paperCitations: SemanticPaperCitationDetail[] = [];

try {
console.time('Query citations');
paperCitations = await getPaperCitations([...this.selectedPaperIDs]);
console.timeEnd('Query citations');
} catch (e) {
await new Promise<void>(resolve =>
setTimeout(() => {
resolve();
}, 1000)
);
await this.updateCitations(retry - 1);
return;
}

// Find and store collaborators
for (const paper of this.papers) {
Expand Down
1 change: 0 additions & 1 deletion src/recrec-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default {

const newRequest = new Request(request, {
headers: {
...request.headers,
'x-api-key': `${env.SEMANTIC_API}`,
},
body: request.body,
Expand Down

0 comments on commit c7150c0

Please sign in to comment.