Communication between main process and sandboxed processors
Created by: alolis
Hello,
I am trying to figure out if there is a way to communicate from the processors
with the main process (and vice versa) and send custom events. The reason is that I would like a processor to be able to emit events that the main process will be able to catch and do some side effects will the processor is still running. If everything was under the same process a custom EventEmitter
would have been sufficient but unfortunately, this will not work with a sandboxed environment.
-
From what I understand
bull
usesprocess.send
andprocess.on
in order to achieve communication between main process and the forked child processes. Is there a way to access thechild.send
method somehow from within the processor in order to send events to the parent while the main process waits withprocess.on
? -
Would it be easier to refactor the
job
that is passed to theprocessor
to be able to emit events via the underlying queue (which already inherits fromEventEmitter
) and to be able to dojob.emit('custom-event', data)
from within theprocessor
and then on the main processqueue.on('custom-event, handler)
? -
Any other alternatives? I was thinking Redis
pub/sub
system since it's already there and I can use that for now if no other way viabull
is possible at the moment.
Thank you for your time.