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
Polling publishers #51
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
polling_timeout = get_polling_timeout() | ||
|
||
while time.time() - starting_time < polling_timeout: | ||
live_page = get_object_or_404(self.model, channel_id=channel_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point this might be optimized since when many people watch the live-stream they will essentially all be doing many identical queries to the database all the time. But database caching like django-cachalot will already help out in cases like this I think (only when you have considerably many users).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, do we support it out of the box and define a boolean setting like WAGTAIL_LIVE_USE_CACHALOT
or shall we just mention in the docs that this optimisation is possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just mention this possibility. If people use e.g. cachalot it will be automatically fixed, so no setting is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good👍
(float) timestamp of the last update received in the client side. | ||
""" | ||
|
||
return float(request.GET.get("last_update_ts")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: what if the request doesn't have a last_update_ts
parameter? Should we return something else instead? Maybe None
but code that calls this method would have to handle that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this can happen only if page.latest_revision_created_at
is None
. And if that happens, we will be in trouble sooner since we call the timestamp
method on None object here. So, we need to handle it from there I think. How do you suggest to handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, ok. Maybe we shouldn't worry too much and just return a 400 bad request response to the client if it doesn't include a last_update_ts
parameter.
This PR adds a
PollingPublisherMixin
for publishers using the polling technique.It also adds an
IntervalPollingPublisher
and aLongPollingPublisher
.I haven't added tests yet, I want to have a feedback on the design first.
To try it out with the testapp, checkout this branch (
polling-publisher
).Here are the steps to take if you want to test the interval polling publisher:
Add this to your
settings.py
file:WAGTAIL_LIVE_PUBLISHER = "wagtail_live.publishers.IntervalPollingPublisher"
Add
wagtail_live
urls intests.urls
like this:BlogPage
model and add the following:Create a live page in the admin interface with channel_id=test_channel for example
Head to http://127.0.0.1:8000/wagtail_live_interface/channels and create a channel with the same name as the BlogPage created, in this example test_channel
(Optional) You can also add a
WAGTAIL_LIVE_POLLING_INTERVAL
value in milliseconds in your settings.We need to set
DEBUG
toTrue
in order to get static files served.And it should be fine.
The steps to take for the long polling publisher are similar with these differences:
WAGTAIL_LIVE_PUBLISHER = "wagtail_live.publishers.LongPollingPublisher"
Create a template for
BlogPage
model and add the following:WAGTAIL_LIVE_POLLING_TIMEOUT
value in seconds in your settings.Additional remarks
From django docs, long polling is a good candidate for async views:
I tried to make an
AsyncLongPollingPublisher
but I don't think it changes a lot under WSGI but maybe we can add it for apps running on ASGI?