Showing real-time pubsub status on user dashboards. Opening up real-time for everybody.

This commit is contained in:
Samuel Clay 2012-04-02 18:48:41 -07:00
parent 070c37ccba
commit 61f2ced74b
9 changed files with 56 additions and 23 deletions

View file

@ -6,8 +6,6 @@ import requests
import re import re
from django.conf import settings from django.conf import settings
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse, Resolver404
from django.db import models from django.db import models
from django.utils.hashcompat import sha_constructor from django.utils.hashcompat import sha_constructor
@ -48,12 +46,12 @@ class PushSubscriptionManager(models.Manager):
callback = "http://push.newsblur.com/push/%s" % subscription.pk # + callback_path callback = "http://push.newsblur.com/push/%s" % subscription.pk # + callback_path
response = self._send_request(hub, { response = self._send_request(hub, {
'hub.mode': 'subscribe', 'hub.mode' : 'subscribe',
'hub.callback': callback, 'hub.callback' : callback,
'hub.topic': topic, 'hub.topic' : topic,
'hub.verify': ['async', 'sync'], 'hub.verify' : ['async', 'sync'],
'hub.verify_token': subscription.generate_token('subscribe'), 'hub.verify_token' : subscription.generate_token('subscribe'),
'hub.lease_seconds': lease_seconds, 'hub.lease_seconds' : lease_seconds,
}) })
if response.status_code == 204: if response.status_code == 204:

4
fabfile.py vendored
View file

@ -114,6 +114,10 @@ def deploy_code(copy_assets=False, full=False):
run('kill -HUP `cat logs/gunicorn.pid`') run('kill -HUP `cat logs/gunicorn.pid`')
run('curl -s http://%s > /dev/null' % env.host) run('curl -s http://%s > /dev/null' % env.host)
run('curl -s http://%s/api/add_site_load_script/ABCDEF > /dev/null' % env.host) run('curl -s http://%s/api/add_site_load_script/ABCDEF > /dev/null' % env.host)
def deploy_node():
with cd(env.NEWSBLUR_PATH):
run('sudo supervisorctl restart node')
def restart_gunicorn(): def restart_gunicorn():
with cd(env.NEWSBLUR_PATH): with cd(env.NEWSBLUR_PATH):

View file

@ -3619,7 +3619,20 @@ background: transparent;
margin-right: 12px; margin-right: 12px;
} }
.NB-module .NB-module-content-account-realtime {
background: transparent url('/media/img/reader/realtime_spinner.gif') no-repeat 0 1px;
font-size: 11px;
text-transform: uppercase;
color: #D8BD70;
font-weight: bold;
float: right;
width: 16px;
height: 16px;
margin: 0 4px 0 0;
}
.NB-module .NB-module-content-account-realtime.NB-error {
background: transparent url('/media/img/reader/realtime_spinner_error.gif') no-repeat 0 1px;
}
.NB-module .NB-module-item { .NB-module .NB-module-item {
position: relative; position: relative;
min-height: 77px; min-height: 77px;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

View file

@ -299,6 +299,10 @@
$('.NB-task-add').tipsy('disable'); $('.NB-task-add').tipsy('disable');
$('.NB-task-manage').tipsy('disable'); $('.NB-task-manage').tipsy('disable');
} }
$('.NB-module-content-account-realtime').tipsy({
gravity: 's',
delayIn: 0
});
}, },
save_feed_pane_size: function(w, pane, $pane, state, options, name) { save_feed_pane_size: function(w, pane, $pane, state, options, name) {
@ -5257,10 +5261,12 @@
setup_socket_realtime_unread_counts: function(force) { setup_socket_realtime_unread_counts: function(force) {
if (!force && NEWSBLUR.Globals.is_anonymous) return; if (!force && NEWSBLUR.Globals.is_anonymous) return;
if (!force && !NEWSBLUR.Globals.is_premium) return; // if (!force && !NEWSBLUR.Globals.is_premium) return;
if (this.socket && !this.socket.socket.connected) {
if (force || !this.socket) { this.socket.socket.connect();
this.socket = this.socket || io.connect('http://' + window.location.hostname + ':8888'); } else if (force || !this.socket || !this.socket.socket.connected) {
var server = window.location.protocol + '//' + window.location.hostname + ':8888';
this.socket = this.socket || io.connect(server);
// this.socket.refresh_feeds = _.debounce(_.bind(this.force_feeds_refresh, this), 1000*10); // this.socket.refresh_feeds = _.debounce(_.bind(this.force_feeds_refresh, this), 1000*10);
this.socket.on('connect', _.bind(function() { this.socket.on('connect', _.bind(function() {
@ -5273,12 +5279,22 @@
this.flags.feed_refreshing_in_realtime = true; this.flags.feed_refreshing_in_realtime = true;
this.setup_feed_refresh(); this.setup_feed_refresh();
$('.NB-module-content-account-realtime').attr('title', 'Updating in real-time').removeClass('NB-error');
}, this)); }, this));
this.socket.on('disconnect', _.bind(function() { this.socket.on('disconnect', _.bind(function() {
console.log(["Lost connection to real-time pubsub. Falling back to polling."]); console.log(["Lost connection to real-time pubsub. Falling back to polling."]);
this.flags.feed_refreshing_in_realtime = false;
this.setup_feed_refresh(); this.setup_feed_refresh();
$('.NB-module-content-account-realtime').attr('title', 'Polling for updates...').addClass('NB-error');
}, this));
this.socket.on('error', _.bind(function() {
console.log(["Can't connect to real-time pubsub."]);
this.flags.feed_refreshing_in_realtime = false;
$('.NB-module-content-account-realtime').attr('title', 'Polling for updates...').addClass('NB-error');
_.delay(_.bind(this.setup_socket_realtime_unread_counts, this), 60*1000);
}, this)); }, this));
} }
}, },
send_socket_active_feeds: function() { send_socket_active_feeds: function() {
@ -5309,10 +5325,9 @@
if (feed_count > 500) { if (feed_count > 500) {
refresh_interval *= 1.5; refresh_interval *= 1.5;
} }
if (this.flags['feed_refreshing_in_realtime'] && !this.flags['has_unfetched_feeds']) { if (this.flags['feed_refreshing_in_realtime'] && !this.flags['has_unfetched_feeds'] &&
if (this.socket && this.socket.socket.connected) { this.socket && this.socket.socket.connected) {
refresh_interval *= 20; refresh_interval *= 20;
}
} }
if (new_feeds && feed_count < 250) { if (new_feeds && feed_count < 250) {

View file

@ -6,7 +6,8 @@ REDIS_SERVER = if process.env.NODE_ENV == 'dev' then 'localhost' else 'db01'
client = redis.createClient 6379, REDIS_SERVER client = redis.createClient 6379, REDIS_SERVER
io.sockets.on 'connection', (socket) -> io.sockets.on 'connection', (socket) ->
console.log " ---> New connection brings total to #{io.sockets.clients().length} consumers." console.log " ---> New connection brings total to" +
" #{io.sockets.clients().length} consumers."
socket.on 'subscribe:feeds', (feeds, username) -> socket.on 'subscribe:feeds', (feeds, username) ->
socket.subscribe?.end() socket.subscribe?.end()
socket.subscribe = redis.createClient 6379, REDIS_SERVER socket.subscribe = redis.createClient 6379, REDIS_SERVER
@ -20,5 +21,6 @@ io.sockets.on 'connection', (socket) ->
socket.on 'disconnect', () -> socket.on 'disconnect', () ->
socket.subscribe?.end() socket.subscribe?.end()
console.log " ---> [] Disconnect, there are now #{io.sockets.clients().length-1} consumers." console.log " ---> [] Disconnect, there are now" +
" #{io.sockets.clients().length-1} consumers."

View file

@ -12,7 +12,7 @@
client = redis.createClient(6379, REDIS_SERVER); client = redis.createClient(6379, REDIS_SERVER);
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
console.log(" ---> New connection brings total to " + (io.sockets.clients().length) + " consumers."); console.log(" ---> New connection brings total to" + (" " + (io.sockets.clients().length) + " consumers."));
socket.on('subscribe:feeds', function(feeds, username) { socket.on('subscribe:feeds', function(feeds, username) {
var _ref; var _ref;
if ((_ref = socket.subscribe) != null) _ref.end(); if ((_ref = socket.subscribe) != null) _ref.end();
@ -27,7 +27,7 @@
return socket.on('disconnect', function() { return socket.on('disconnect', function() {
var _ref; var _ref;
if ((_ref = socket.subscribe) != null) _ref.end(); if ((_ref = socket.subscribe) != null) _ref.end();
return console.log(" ---> [] Disconnect, there are now " + (io.sockets.clients().length - 1) + " consumers."); return console.log(" ---> [] Disconnect, there are now" + (" " + (io.sockets.clients().length - 1) + " consumers."));
}); });
}); });

View file

@ -280,8 +280,9 @@
<h3 class="NB-module-content-header"> <h3 class="NB-module-content-header">
{% if user.profile.is_premium %} {% if user.profile.is_premium %}
<span class="NB-module-content-subtitle"> <span class="NB-module-content-subtitle">
{{ active_count }} site{{ active_count|pluralize }} {{ active_count }} site{{ active_count|pluralize }}
</span> </span>
<div class="NB-module-content-account-realtime" title=""></div>
Premium Account Premium Account
{% else %} {% else %}
<span class="NB-module-content-subtitle"> <span class="NB-module-content-subtitle">
@ -292,7 +293,7 @@
</h3> </h3>
<div class="NB-module-item-title"> <div class="NB-module-item-title">
{% if user.profile.is_premium %} {% if user.profile.is_premium %}
{% else %} {% else %}
<div class="NB-modal-submit"> <div class="NB-modal-submit">