Permalink
Browse files

fixes to the agent example

git-svn-id: http://evserver.googlecode.com/svn/trunk@89 e9bb6d7e-af12-11dd-bad7-87afd3b02348
  • Loading branch information...
majek04
majek04 committed Feb 10, 2009
1 parent 2212350 commit 9f2eb2f2b6961740b029572de0ab7ff298bed56f
@@ -18,7 +18,7 @@ <h3>Real-time referers log:</h3>
<script>
var p = document.getElementById('p');
function user_callback(data){
- if(!data)
+ if(!data || data=='ping')
return;
var i = p.innerHTML
p.innerHTML = i + '<br>'+data;
@@ -9,5 +9,6 @@
(r'^$', views.index),
(r'^index.html$', views.index),
(r'^comet.html$', views.comet),
+ (r'^favicon.ico$', views.empty),
)
@@ -27,23 +27,22 @@
log = logging.getLogger(os.path.basename(__file__))
-cached_publisher_connection = None
-cached_publisher_channel = None
-
def send_amqp_message(msg_body):
- global cached_publisher_connection, cached_publisher_channel
- if not cached_publisher_channel:
- conn = amqp.Connection('localhost', userid='guest', password='guest')
- ch = conn.channel()
- ch.access_request('/data', active=True, write=True)
- ch.exchange_declare('myfan', 'fanout', auto_delete=True)
+ # conn should be cached
+ conn = amqp.Connection('localhost', userid='guest', password='guest')
+ ch = conn.channel()
+ ch.access_request('/data', active=True, write=True)
+ ch.exchange_declare('myfan', 'fanout', auto_delete=True)
- cached_publisher_connection = conn
- cached_publisher_channel = ch
+ cached_publisher_connection = conn
+ cached_publisher_channel = ch
msg = amqp.Message(msg_body, content_type='text/plain')
cached_publisher_channel.basic_publish(msg, 'myfan')
+ ch.close()
+ conn.close()
+
# that is a raw hack that doesn't scale!
@@ -56,7 +55,7 @@ def index(request):
referer = request.META.get('HTTP_REFERER', '')
agent = request.META.get('HTTP_USER_AGENT', '')
- msg = cgi.escape('#%i %s: %r %r' % (counter, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), referer, agent))
+ msg = cgi.escape('#%i %s: %r %r' % (counter, datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'), agent, referer))
send_amqp_message(msg)
state_cache.append(msg)
if len(state_cache) > 30: state_cache.pop(0) # remove first element
@@ -80,7 +79,8 @@ def set_ridiculously_high_buffers(sd):
break
def comet(request):
- t = evserver.transports.get_transport(request.GET.get('transport','basic'))
+ t = evserver.transports.get_transport(request.GET.get('transport','basic'),
+ callback=request.GET.get('callback','c0'))
# setup the amqp subscriber
msgs = []
@@ -142,3 +142,6 @@ def iterator():
return response
+
+def empty(request):
+ return HttpResponse('', mimetype="text/html")

0 comments on commit 9f2eb2f

Please sign in to comment.