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');
}
co