Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
miya committed Oct 18, 2024
1 parent 87a70f6 commit df8e58f
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@ class ThreadDeletionCronService {
return;
}

// Executed at 0 minutes of every hour
// const cronSchedule = '0 * * * *';
const openaiService = getOpenaiService();
if (openaiService == null) {
throw new Error('OpenAI service is not initialized');
}

// debug mode
const cronSchedule = '* * * * *';
this.openaiService = openaiService;

// Executed at 0 minutes of every hour
const cronSchedule = '0 * * * *';

this.cronJob?.stop();
this.cronJob = this.generateCronJob(cronSchedule);
this.cronJob.start();
}

private async executeJob(): Promise<void> {
const openaiService = getOpenaiService();

// Delete only 100 by rateLimit countermeasure on OpenAI side
await openaiService?.deleteExpiredThreads(DELETE_LIMIT);
// Must be careful of OpenAI's rate limit
// Delete up to 100 threads per hour
await this.openaiService.deleteExpiredThreads(DELETE_LIMIT);
}

private generateCronJob(cronSchedule: string) {
Expand Down

0 comments on commit df8e58f

Please sign in to comment.