Skip to content

Commit

Permalink
feat(next/api): language detect print more info
Browse files Browse the repository at this point in the history
  • Loading branch information
uffy committed May 24, 2024
1 parent cfcfb2b commit 8eeb095
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions next/api/src/service/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class TicketService {
},
});
this.detectLangQueue.process((job) => {
return this.detectTicketLanguage(job.data.ticketId);
return this.detectTicketLanguage(job);
});
}

Expand Down Expand Up @@ -150,7 +150,8 @@ export class TicketService {
return differenceInMilliseconds(new Date(), ticket.closedAt) <= evaluationConfig.timeLimit;
}

async detectTicketLanguage(ticketId: string) {
async detectTicketLanguage(job: Job<DetectTicketLanguageJobData>) {
const { ticketId } = job.data;
const ticket = await Ticket.find(ticketId, { useMasterKey: true });
if (!ticket) {
return;
Expand All @@ -161,8 +162,14 @@ export class TicketService {
return;
}

const translateResult = await translateService.translate(text);
console.log(`[TicketService] detecting language for ticket ${ticket.id}: ${text}, result: ${JSON.stringify(translateResult)}`);
const start = performance.now();
let translateResult;
try{
translateResult = await translateService.translate(text);
} finally {
const end = performance.now();
console.log(`[TicketService] detecting language for ticket ${ticket.nid}: ${text}, result: ${translateResult?.from}, attempts: ${job.attemptsMade}, time: ${end - start}ms`);
}

if (!translateResult) {
return;
Expand Down

0 comments on commit 8eeb095

Please sign in to comment.