Permalink
Browse files

fixes to the agent example

git-svn-id: http://evserver.googlecode.com/svn/trunk@88 e9bb6d7e-af12-11dd-bad7-87afd3b02348
  • Loading branch information...
majek04
majek04 committed Feb 10, 2009
1 parent 0c42eae commit 2212350558a730fad6c53ae71339da899c34905a
@@ -18,9 +18,11 @@ <h3>Real-time referers log:</h3>
<script>
var p = document.getElementById('p');
function user_callback(data){
+ if(!data)
+ return;
var i = p.innerHTML
p.innerHTML = i + '<br>'+data;
p.scrollTop = p.scrollHeight;
}
-close_comet_function = comet_connection('./comet/', user_callback);
+close_comet_function = comet_connection('./comet.html', user_callback);
</script>
@@ -8,6 +8,6 @@
(r'^static/(?P<path>.*)$', django.views.static.serve, {'document_root': settings.STATIC_DIR}),
(r'^$', views.index),
(r'^index.html$', views.index),
- (r'^comet/$', views.comet),
+ (r'^comet.html$', views.comet),
)
@@ -20,7 +20,9 @@
import socket
import evserver.transports
import logging
+import cgi
import amqplib.client_0_8 as amqp
+
logging.getLogger('amqplib').setLevel(logging.INFO) # ignore msgs from there
log = logging.getLogger(os.path.basename(__file__))
@@ -43,7 +45,6 @@ def send_amqp_message(msg_body):
cached_publisher_channel.basic_publish(msg, 'myfan')
-import cgi
# that is a raw hack that doesn't scale!
counter = 0
@@ -55,7 +56,7 @@ def index(request):
referer = request.META.get('HTTP_REFERER', '')
agent = request.META.get('HTTP_USER_AGENT', '')
- msg = cgi.escape('#%i: %r %r' % (counter, referer, agent))
+ msg = cgi.escape('#%i %s: %r %r' % (counter, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), referer, agent))
send_amqp_message(msg)
state_cache.append(msg)
if len(state_cache) > 30: state_cache.pop(0) # remove first element
@@ -115,11 +116,13 @@ def iterator():
except (TypeError,), e:
pass
+ if not msgs:
+ yield t.write('ping')
while msgs:
msg = msgs.pop(0)
yield t.write(msg)
- yield request.environ['x-wsgiorg.fdevent.readable'](conn.transport.sock)
+ yield request.environ['x-wsgiorg.fdevent.readable'](conn.transport.sock, 60)
except GeneratorExit:
pass

0 comments on commit 2212350

Please sign in to comment.