Skip to content

Commit

Permalink
Merge pull request #9347 from weseek/feat/156766-set-the-maximum-numb…
Browse files Browse the repository at this point in the history
…er-of-minutes-until-the-request-in-an-environment-variable

feat: Set the maximum number of minutes until the request in an environment variable
  • Loading branch information
mergify[bot] authored Nov 5, 2024
2 parents 1b6af1a + 4833428 commit a187f0f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ThreadDeletionCronService {

threadDeletionCronExpression: string;

threadDeletionCronMaxMinutesUntilRequest: number;

threadDeletionBarchSize: number;

threadDeletionApiCallInterval: number;
Expand All @@ -35,6 +37,7 @@ class ThreadDeletionCronService {

this.openaiService = openaiService;
this.threadDeletionCronExpression = configManager.getConfig('crowi', 'openai:threadDeletionCronExpression');
this.threadDeletionCronMaxMinutesUntilRequest = configManager.getConfig('crowi', 'app:openaiThreadDeletionCronMaxMinutesUntilRequest');
this.threadDeletionBarchSize = configManager.getConfig('crowi', 'openai:threadDeletionBarchSize');
this.threadDeletionApiCallInterval = configManager.getConfig('crowi', 'openai:threadDeletionApiCallInterval');

Expand All @@ -51,8 +54,8 @@ class ThreadDeletionCronService {
private generateCronJob() {
return nodeCron.schedule(this.threadDeletionCronExpression, async() => {
try {
// Sleep for a random number of minutes between 0 and 60 to distribute request load
const randomMilliseconds = getRandomIntInRange(0, 60) * 60 * 1000;
// Random fractional sleep to distribute request timing among GROWI apps
const randomMilliseconds = getRandomIntInRange(0, this.threadDeletionCronMaxMinutesUntilRequest) * 60 * 1000;
this.sleep(randomMilliseconds);

await this.executeJob();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class VectorStoreFileDeletionCronService {

vectorStoreFileDeletionCronExpression: string;

vectorStoreFileDeletionCronMaxMinutesUntilRequest: number;

vectorStoreFileDeletionBarchSize: number;

vectorStoreFileDeletionApiCallInterval: number;
Expand All @@ -35,6 +37,7 @@ class VectorStoreFileDeletionCronService {

this.openaiService = openaiService;
this.vectorStoreFileDeletionCronExpression = configManager.getConfig('crowi', 'openai:vectorStoreFileDeletionCronExpression');
this.vectorStoreFileDeletionCronMaxMinutesUntilRequest = configManager.getConfig('crowi', 'app:openaiVectorStoreFileDeletionCronMaxMinutesUntilRequest');
this.vectorStoreFileDeletionBarchSize = configManager.getConfig('crowi', 'openai:vectorStoreFileDeletionBarchSize');
this.vectorStoreFileDeletionApiCallInterval = configManager.getConfig('crowi', 'openai:vectorStoreFileDeletionApiCallInterval');

Expand All @@ -51,8 +54,8 @@ class VectorStoreFileDeletionCronService {
private generateCronJob() {
return nodeCron.schedule(this.vectorStoreFileDeletionCronExpression, async() => {
try {
// Sleep for a random number of minutes between 0 and 60 to distribute request load
const randomMilliseconds = getRandomIntInRange(0, 60) * 60 * 1000;
// Random fractional sleep to distribute request timing among GROWI apps
const randomMilliseconds = getRandomIntInRange(0, this.vectorStoreFileDeletionCronMaxMinutesUntilRequest) * 60 * 1000;
this.sleep(randomMilliseconds);

await this.executeJob();
Expand Down
12 changes: 12 additions & 0 deletions apps/app/src/server/service/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ As this system is a Retrieval Augmented Generation (RAG), focus on answering que
type: ValueType.STRING,
default: '0 * * * *', // every hour
},
OPENAI_THREAD_DELETION_CRON_MAX_MINUTES_UNTIL_REQUEST: {
ns: 'crowi',
key: 'app:openaiThreadDeletionCronMaxMinutesUntilRequest',
type: ValueType.NUMBER,
default: 60,
},
OPENAI_THREAD_DELETION_BARCH_SIZE: {
ns: 'crowi',
key: 'openai:threadDeletionBarchSize',
Expand All @@ -832,6 +838,12 @@ As this system is a Retrieval Augmented Generation (RAG), focus on answering que
type: ValueType.STRING,
default: '0 * * * *', // every hour
},
OPENAI_VECTOR_STORE_FILE_DELETION_CRON_MAX_MINUTES_UNTIL_REQUEST: {
ns: 'crowi',
key: 'app:openaiVectorStoreFileDeletionCronMaxMinutesUntilRequest',
type: ValueType.NUMBER,
default: 60,
},
OPENAI_VECTOR_STORE_FILE_DELETION_BARCH_SIZE: {
ns: 'crowi',
key: 'openai:vectorStoreFileDeletionBarchSize',
Expand Down

0 comments on commit a187f0f

Please sign in to comment.