Open alolis opened 6 years ago
@alolis Could you accomplish what you're trying to do by creating another queue, eventQueue, that is consumed by your main process and which your processors publish events-as-jobs to?
...and do some side effects will the processor is still running.
Not sure if that means the processor needs to use the result of the side effects or if it just needs to trigger something that leads to those side effects. If the former, you should be able to listen to the eventQueue's events in your processor to determine when the event-job has been processed.
@gcox it's been a while since the question but I did go with (3) as I also mention here.
In my case the processor did not need the results of the side effects but the communication had to go two ways.
I kinda did a hack on this one and pass the custom event to job.progress method.
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 customEventEmitter
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.