django-eventstream
django-eventstream copied to clipboard
Option for blocking publish
Feature request: Support for the "blocking" option from django_grip in eventstream.
Rationale: We are running into an issue where some messages are not sent from celery workers. I suspect what is happening is that the celery worker process is exiting (including daemon threads) before the event is published by the daemon thread in pubcontrol.
We have logging in place just before calling eventstream.send_event
, and the call is being made by the celery workers, but the message is not received by the client. This is a intermittent problem. We observed this with a self-hosted pushpin proxy, and continue to see this using fanout.io.
Clarification of python methods:
in django_grip the publish
function accepts blocking
as an argument. django-eventstream does not provide a means to set that argument, always falling back to the default of False
.
Perhaps a good model would be to send arbitrary **kwargs
, as I can think of use cases for a callback as well.
Interesting. There's an atexit
handler in pubcontrol to ensure messages get flushed, but possibly that doesn't work in all situations. Being able to do a blocking send seems reasonable. I've committed something for that.
However, I just realized this may not be needed because you can manually invoke the same waiting effect as the atexit handler like this:
from django_grip import get_pubcontrol
send_event(...)
get_pubcontrol().wait_all_sent()
Let me know if that works.
Thanks for the reply. Yes, that looks like it should do what I want. I will try it out. I would expect the atexit handling to work as well.