Perf system plugin and worker (#2126)

* perf: worker pool

* perf: worker register

* perf: worker controller

* perf: system plugin worker

* perf: system plugin worker

* perf: worker

* perf: worker

* worker timeout

* perf: copy icon
This commit is contained in:
Archer
2024-07-23 11:23:42 +08:00
committed by GitHub
parent a4787bce5c
commit e99c91aaa6
34 changed files with 433 additions and 235 deletions

View File

@@ -4,10 +4,12 @@ import { FastGPTProUrl, isProduction } from '../service/common/system/constants'
import { GET, POST } from '@fastgpt/service/common/api/plusRequest';
import { SystemPluginTemplateItemType } from '@fastgpt/global/core/workflow/type';
import { cloneDeep } from 'lodash';
import { WorkerNameEnum, runWorker } from '@fastgpt/service/worker/utils';
let list = [
'getTime',
'fetchUrl',
// Run in main thread
const staticPluginList = ['getTime', 'fetchUrl'];
// Run in worker thread (Have npm packages)
const packagePluginList = [
'mathExprVal',
'duckduckgo',
'duckduckgo/search',
@@ -16,6 +18,8 @@ let list = [
'duckduckgo/searchVideo'
];
const list = [...staticPluginList, ...packagePluginList];
/* Get plugins */
export const getCommunityPlugins = () => {
return list.map<SystemPluginTemplateItemType>((name) => {
@@ -58,8 +62,7 @@ export const getSystemPluginTemplates = async (refresh = false) => {
};
export const getCommunityCb = async () => {
// Do not modify the following code
const loadModule = async (name: string) => {
const loadCommunityModule = async (name: string) => {
const module = await import(`./src/${name}/index`);
return module.default;
};
@@ -70,7 +73,14 @@ export const getCommunityCb = async () => {
try {
return {
name,
cb: await loadModule(name)
cb: staticPluginList.includes(name)
? await loadCommunityModule(name)
: (e: any) => {
return runWorker(WorkerNameEnum.systemPluginRun, {
pluginName: name,
data: e
});
}
};
} catch (error) {}
})