bull在设置处理器时,如果处理器是字符串类型则认为它是js脚本路径
queue.process('my-processor.js')
这种情况下会在单独的 node 进程中运行进程函数。这类进程称为沙盒进程
如果沙盒崩溃,不会影响任何其他进程,并且会自动生成一个新进程来取代它。
setHandler 方法中,会使用沙盒包装指定的处理器脚本,然后用进程池来运行它
if (typeof handler === 'string') {
const supportedFileTypes = ['.js', '.ts', '.flow', '.cjs'];
const processorFile =
handler +
(supportedFileTypes.includes(path.extname(handler)) ? '' : '.js');
if (!fs.existsSync(processorFile)) {
throw new Error('File ' + processorFile + ' does not exist');
}
const isSharedChildPool = this.settings.isSharedChildPool;
this.childPool =
this.childPool || require('./process/child-pool')(isSharedChild
本文详细介绍了Bull任务队列在处理处理器时如何使用沙箱和进程池。当处理器为JS脚本路径时,Bull会创建沙盒进程,确保进程崩溃不影响其他进程。进程池通过ChildPool管理,根据isSharedChildPool决定是否共享。初始化子进程时,使用IPC通信,子进程在完成任务后返回IDLE状态。沙箱调用子进程执行任务并监听各种事件。然而,Bull进程池没有最大数量限制,可能导致过多子进程同时存在。
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



