mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-04 14:41:14 +00:00
Add support for preloading Node Addons via env var
Introduces logic to preload a Node Addon in the worker process if the NAPCAT_PRELOAD_NODE_ADDON_PATH environment variable is set. Logs success or failure of the preload operation for better debugging and flexibility.
This commit is contained in:
parent
81a0c07922
commit
1b4d604e32
@ -281,6 +281,18 @@ async function startWorkerProcess (): Promise<void> {
|
||||
throw new Error('进程管理器未初始化');
|
||||
}
|
||||
|
||||
// 预加载 Node Addon(如果设置了环境变量)
|
||||
const preloadAddonPath = process.env['NAPCAT_PRELOAD_NODE_ADDON_PATH'];
|
||||
if (preloadAddonPath) {
|
||||
try {
|
||||
const os = await import('os');
|
||||
process.dlopen({ exports: {} }, preloadAddonPath, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
|
||||
logger.log(`[NapCat] [Worker] 已预加载 Node Addon: ${preloadAddonPath}`);
|
||||
} catch (error) {
|
||||
logger.logError(`[NapCat] [Worker] 预加载 Node Addon 失败: ${preloadAddonPath}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// 监听来自父进程的消息
|
||||
processManager.onParentMessage((msg: unknown) => {
|
||||
if (typeof msg === 'object' && msg !== null && 'type' in msg) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user