Skip to content

Commit

Permalink
Refactoring real-time socketio clientside to fix multiple client upda…
Browse files Browse the repository at this point in the history
…tes.
  • Loading branch information
samuelclay committed Apr 16, 2013
1 parent 48cab9a commit 76cbbd8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
10 changes: 5 additions & 5 deletions config/nginx.newsblur.conf
Expand Up @@ -91,11 +91,11 @@ server {
}

location /munin/ {
alias /var/cache/munin/www/;
# fastcgi_split_path_info ^(/munin)(.*);
# fastcgi_param PATH_INFO $fastcgi_path_info;
# fastcgi_pass unix:/var/run/munin/fcgi-html.sock;
# include fastcgi_params;
# alias /var/cache/munin/www/;
fastcgi_split_path_info ^(/munin)(.*);
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/munin/fcgi-html.sock;
include fastcgi_params;
}

location ^~ /cgi-bin/munin-cgi-graph/ {
Expand Down
1 change: 1 addition & 0 deletions fabfile.py
Expand Up @@ -876,6 +876,7 @@ def setup_munin():
sudo('/etc/init.d/munin-node restart')
with settings(warn_only=True):
sudo('chown nginx.www-data munin-cgi*')
sudo('chmod a+rw /var/log/munin/*')
with settings(warn_only=True):
sudo('/etc/init.d/spawn_fcgi_munin_graph start')
sudo('/etc/init.d/spawn_fcgi_munin_html start')
Expand Down
57 changes: 29 additions & 28 deletions media/js/newsblur/reader/reader.js
Expand Up @@ -3884,40 +3884,41 @@
this.socket.on('connect', _.bind(function() {
var active_feeds = this.send_socket_active_feeds();
// NEWSBLUR.log(["Connected to real-time pubsub with " + active_feeds.length + " feeds."]);
this.socket.removeAllListeners('feed:update');
this.socket.on('feed:update', _.bind(function(feed_id, message) {
NEWSBLUR.log(['Real-time feed update', feed_id, message]);
this.feed_unread_count(feed_id);
}, this));

this.socket.removeAllListeners(NEWSBLUR.Globals.username);
this.socket.on('user:update', _.bind(function(username, feed_id) {
if (this.flags.social_view) return;
if (_.string.contains(feed_id, 'feed:')) {
feed_id = parseInt(feed_id.replace('feed:', ''), 10);
var active_feed_ids = [];
if (this.active_folder && this.active_folder.length) {
active_feed_ids = this.active_folder.feed_ids_in_folder();
}
if (feed_id != this.active_feed &&
!_.contains(active_feed_ids, feed_id)) {
NEWSBLUR.log(['Real-time user update', username, feed_id]);
this.feed_unread_count(feed_id);
}
} else if (_.string.contains(feed_id, 'social:')) {
if (feed_id != this.active_feed) {
NEWSBLUR.log(['Real-time user update', username, feed_id]);
this.feed_unread_count(feed_id);
}
}
}, this));

this.flags.feed_refreshing_in_realtime = true;
this.setup_feed_refresh();

// $('.NB-module-content-account-realtime-subtitle').html($.make('b', 'Updating in real-time'));
$('.NB-module-content-account-realtime').attr('title', 'Updating sites in real-time...').removeClass('NB-error');
}, this));

this.socket.removeAllListeners('feed:update');
this.socket.on('feed:update', _.bind(function(feed_id, message) {
NEWSBLUR.log(['Real-time feed update', feed_id, message]);
this.feed_unread_count(feed_id);
}, this));

this.socket.removeAllListeners(NEWSBLUR.Globals.username);
this.socket.on('user:update', _.bind(function(username, feed_id) {
if (this.flags.social_view) return;
if (_.string.contains(feed_id, 'feed:')) {
feed_id = parseInt(feed_id.replace('feed:', ''), 10);
var active_feed_ids = [];
if (this.active_folder && this.active_folder.length) {
active_feed_ids = this.active_folder.feed_ids_in_folder();
}
if (feed_id != this.active_feed &&
!_.contains(active_feed_ids, feed_id)) {
NEWSBLUR.log(['Real-time user update', username, feed_id]);
this.feed_unread_count(feed_id);
}
} else if (_.string.contains(feed_id, 'social:')) {
if (feed_id != this.active_feed) {
NEWSBLUR.log(['Real-time user update', username, feed_id]);
this.feed_unread_count(feed_id);
}
}
}, this));

this.socket.on('disconnect', _.bind(function() {
NEWSBLUR.log(["Lost connection to real-time pubsub. Falling back to polling."]);
this.flags.feed_refreshing_in_realtime = false;
Expand Down
13 changes: 8 additions & 5 deletions utils/tlnb.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os
import re
import select
import subprocess
import sys
Expand All @@ -12,11 +11,15 @@
'push',
]

def main(role="app", role2="dev"):
def main(role="app", role2="dev", command=None, path=None):
streams = list()
path = "/srv/newsblur/logs/newsblur.log"
if not path:
path = "/srv/newsblur/logs/newsblur.log"
if not command:
command = "tail -f"
hosts_path = os.path.expanduser(os.path.join('../secrets-newsblur/configs/hosts.yml'))
hosts = yaml.load(open(hosts_path))

for r in [role, role2]:
if isinstance(hosts[r], dict):
hosts[r] = ["%s:%s" % (hosts[r][k][-1], k) for k in hosts[r].keys()]
Expand All @@ -29,9 +32,9 @@ def main(role="app", role2="dev"):
address = hostname
if 'ec2' in hostname:
s = subprocess.Popen(["ssh", "-i", os.path.expanduser("~/.ec2/sclay.pem"),
address, "tail -f " + path], stdout=subprocess.PIPE)
address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
else:
s = subprocess.Popen(["ssh", address, "tail -f " + path], stdout=subprocess.PIPE)
s = subprocess.Popen(["ssh", address, "%s %s" % (command, path)], stdout=subprocess.PIPE)
s.name = hostname
streams.append(s)

Expand Down

0 comments on commit 76cbbd8

Please sign in to comment.