Shun Miyazawa 1 год назад
Родитель
Сommit
dc1009671a
1 измененных файлов с 19 добавлено и 1 удалено
  1. 19 1
      apps/app/src/features/openai/server/services/thread-deletion-cron.ts

+ 19 - 1
apps/app/src/features/openai/server/services/thread-deletion-cron.ts

@@ -1,14 +1,32 @@
 import nodeCron from 'node-cron';
 
+import { configManager } from '~/server/service/config-manager';
 import loggerFactory from '~/utils/logger';
 
+import ThreadRelationModel from '../models/thread-relation';
+
+import { getOpenaiService, type IOpenaiService } from './openai';
+
+
 const logger = loggerFactory('growi:service:thread-deletion-cron');
 
 class ThreadDeletionCronService {
 
   cronJob: nodeCron.ScheduledTask;
 
+  openaiService: IOpenaiService;
+
   startCron(): void {
+    const isAiEnabled = configManager.getConfig('crowi', 'app:aiEnabled');
+    if (!isAiEnabled) {
+      return;
+    }
+
+    const openaiService = getOpenaiService();
+    if (openaiService == null) {
+      throw new Error('openaiService is not initialized');
+    }
+
     // Executed at 0 minutes of every hour
     // const cronSchedule = '0 * * * *';
 
@@ -25,7 +43,7 @@ class ThreadDeletionCronService {
   }
 
   async executeJob(): Promise<void> {
-    // implement
+    // important
   }
 
   private generateCronJob(cronSchedule: string) {