Skip to content

Commit

Permalink
feat(next/api): set timeout for translate api request and allows to r…
Browse files Browse the repository at this point in the history
…etry failed jobs
  • Loading branch information
uffy committed May 23, 2024
1 parent 62f4d70 commit 7fb21ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public/bundle.js*
public/app.css*
datas/
dist/
.idea/
7 changes: 6 additions & 1 deletion next/api/src/service/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export class TicketService {
this.detectLangQueue = createQueue('ticket_language_detect', {
defaultJobOptions: {
removeOnComplete: true,
removeOnFail: true,
removeOnFail: 1000, // 仅保留 1000 个失败任务
attempts: 3,
backoff: {
type: 'exponential',
delay: 1000,
},
},
});
this.detectLangQueue.process((job) => {
Expand Down
1 change: 1 addition & 0 deletions next/api/src/service/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class TranslateService {
this.fanyiURL,
{ text },
{
timeout: 2000,
headers: {
'x-fanyi-token': this.fanyiToken,
},
Expand Down

0 comments on commit 7fb21ad

Please sign in to comment.