Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Set the maximum number of minutes until the request in an environment variable #9347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading