fix for lp742650

This commit is contained in:
Anthony Young 2011-03-29 16:13:09 -07:00
parent c7555d66e5
commit 620c2dabfa

View File

@ -108,17 +108,17 @@ class AjaxConsoleProxy(object):
return "Server Error" return "Server Error"
def register_listeners(self): def register_listeners(self):
class Callback: class TopicProxy():
def __call__(self, data, message): @staticmethod
if data['method'] == 'authorize_ajax_console': def authorize_ajax_console(context, **kwargs):
AjaxConsoleProxy.tokens[data['args']['token']] = \ AjaxConsoleProxy.tokens[kwargs['token']] = \
{'args': data['args'], 'last_activity': time.time()} {'args': kwargs, 'last_activity': time.time()}
conn = rpc.Connection.instance(new=True) conn = rpc.Connection.instance(new=True)
consumer = rpc.TopicAdapterConsumer( consumer = rpc.TopicAdapterConsumer(
connection=conn, connection=conn,
proxy=TopicProxy,
topic=FLAGS.ajax_console_proxy_topic) topic=FLAGS.ajax_console_proxy_topic)
consumer.register_callback(Callback())
def delete_expired_tokens(): def delete_expired_tokens():
now = time.time() now = time.time()
@ -130,8 +130,7 @@ class AjaxConsoleProxy(object):
for k in to_delete: for k in to_delete:
del AjaxConsoleProxy.tokens[k] del AjaxConsoleProxy.tokens[k]
utils.LoopingCall(consumer.fetch, auto_ack=True, utils.LoopingCall(consumer.fetch, enable_callbacks=True).start(0.1)
enable_callbacks=True).start(0.1)
utils.LoopingCall(delete_expired_tokens).start(1) utils.LoopingCall(delete_expired_tokens).start(1)
if __name__ == '__main__': if __name__ == '__main__':