Files
FastGPT/projects/app/src/service/common/system/volumnMongoWatch.ts
Archer 58745f8c35 4.8.14 test (#3164)
* perf: match base 64 image

* perf: register plugins
2024-11-15 10:35:04 +08:00

37 lines
1.0 KiB
TypeScript

import { getSystemPluginCb } from '@/service/core/app/plugin';
import { initSystemConfig } from '.';
import { createDatasetTrainingMongoWatch } from '@/service/core/dataset/training/utils';
import { MongoSystemConfigs } from '@fastgpt/service/common/system/config/schema';
import { MongoSystemPluginSchema } from '@fastgpt/service/core/app/plugin/systemPluginSchema';
export const startMongoWatch = async () => {
reloadConfigWatch();
refetchSystemPlugins();
createDatasetTrainingMongoWatch();
};
const reloadConfigWatch = () => {
const changeStream = MongoSystemConfigs.watch();
changeStream.on('change', async (change) => {
try {
if (change.operationType === 'insert') {
await initSystemConfig();
console.log('refresh system config');
}
} catch (error) {}
});
};
const refetchSystemPlugins = () => {
const changeStream = MongoSystemPluginSchema.watch();
changeStream.on('change', async (change) => {
setTimeout(() => {
try {
getSystemPluginCb(true);
} catch (error) {}
}, 5000);
});
};