Exemple #1
0
    def get(self):
        c = tornadoredis.Client(connection_pool=CONNECTION_POOL)
        request = self.request
        url_path = request.path

        logger = logging.getLogger('tornado.application')
        logger.info(url_path)

        if self.router.exist_route(url_path):
            # determine timeout
            if url_path in self.timeout_rules:
                timeout = self.timeout_rules[url_path]
            else:
                timeout = self.atm_settings.DEFAULT_TIMEOUT

            query = request.query
            host = self.router.get_route(url_path)
            logger.info(host)

            query_url_path = "%s?%s" % (url_path, query) if query else url_path
            logger.info("Request: %s" % query_url_path)

            exists = yield tornado.gen.Task(c.exists, query_url_path)
            
            if exists:
                print 'exists'
                response = yield tornado.gen.Task(c.get, query_url_path)
                yield tornado.gen.Task(c.disconnect)
                self.write(message_decode(response))
                self.finish()
            else:
                print 'not exsits'
                content_url = "%s%s" % (host, query_url_path)
                content_to_cache = send_message(content_url)
                content_to_cache = message_encode(content_to_cache)

                #cache_result = yield tornado.gen.Task(c.setex, query_url_path, content_to_cache, 3600)
                print query_url_path, len(content_to_cache)
                cache_result = yield tornado.gen.Task(c.setex, query_url_path, 3600, content_to_cache)
                yield tornado.gen.Task(c.disconnect)
                self.write('')
                self.finish()
Exemple #2
0
 def handle_outgoing(self, obj, topic_or_queue='/queue/request'):
     message = message_encode(obj)
     log.debug("send: %r to '%s'" % (obj, topic_or_queue))
     self.mgw.send(topic_or_queue, message)