mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
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:
24
packages/plugins/runtime/worker.ts
Normal file
24
packages/plugins/runtime/worker.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { SystemPluginResponseType } from '../type';
|
||||
import { parentPort } from 'worker_threads';
|
||||
|
||||
const loadModule = async (name: string): Promise<(e: any) => SystemPluginResponseType> => {
|
||||
const module = await import(`../src/${name}/index`);
|
||||
return module.default;
|
||||
};
|
||||
|
||||
parentPort?.on('message', async ({ pluginName, data }: { pluginName: string; data: any }) => {
|
||||
try {
|
||||
const cb = await loadModule(pluginName);
|
||||
parentPort?.postMessage({
|
||||
type: 'success',
|
||||
data: await cb(data)
|
||||
});
|
||||
} catch (error) {
|
||||
parentPort?.postMessage({
|
||||
type: 'error',
|
||||
data: error
|
||||
});
|
||||
}
|
||||
|
||||
process.exit();
|
||||
});
|
Reference in New Issue
Block a user