-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect if code is running in a Bull process or not? #1951
Comments
This is what I've gone with for now: /** Is this code executing in a Bull process? */
export const isBullProcess = process.argv.some(a => a.includes('bull')) |
I am not really sure what you are trying to figure out. Bull does only spawn new processes if you put your process in a separate file as explained here: https://github.com/optimalbits/bull#separate-processes |
I think the request is for something like a Based on how Bull forks sandbox processes today, I think all you can do is check bull/lib/process/child-pool.js Lines 52 to 54 in 06b511a
|
@gabegorelick but that can easily be added in the processor file, just set a global variable or similar... |
I don't want to speak for what @cjdell needs, but that means you processor file can't be used when not running in a sandbox. Take the processor example from the README: module.exports = function(job){
// Do some heavy work
return Promise.resolve(result);
} When using a sandbox process, I can call queue.process(require('/path/to/my/processor.js')); But if the processor needs to be aware of whether it's running in sandbox mode, then you'd need to add some indirection like so: // jobProcessor.js
module.exports = function(job){
if (job.isSandboxed) { ... }
return Promise.resolve(result);
}
// sandbox.js
module.exports = function(job){
job.isSandboxed = true; // or alternatively, set a global variable
return require('./jobProcessor')(job);
} Then the queue processing code can decide whether to use Anyway, I'll shut up now and let others provide real use cases :) |
My use case would be using the same entry file in cases where you'd build your scripts with something like webpack. Ofc you can have your webpack setup create multiple bundles (index.js, worker.js). Instead though, we could only have 1 bundle (index.js) and let that file decide what to do using an environment var (IS_BULL_SANDBOXED=true). // index.js
if (process.env.IS_BULL_SANDBOXED) {
module.exports = function(job) { .... }
} else {
runMainCode();
} |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Is there a reliable way to detect whether the code is running in the main thread or in a Bull process?
I want to use this to avoid making unnecessary requires when the code is running in Bull to keep the process size down.
Thanks
The text was updated successfully, but these errors were encountered: