from tornado.httpserver import HTTPServer from tornado.web import RequestHandler, asynchronous from tornado import escape from tornado.httpclient import AsyncHTTPClient from src.common.logutil import get_logger from src.common.reflectionutil import import_resource, enum from src.common.jsonutil import str2bool, validate, json2dict from src.common.error import FlamesError from src.common.status import UNKNOWN_RESOURCE, USER_NOT_FOUND from tornado.auth import OAuth2Mixin from tornado.gen import Return, coroutine from src.user.service import get_user_auth, update_user_auth #from src.common.cacheutil import get_cache, set_cache HTTP_METHOD = enum(GET = 'GET', POST = 'POST', PUT = 'PUT', DELETE = 'DELETE') _handler_dict = OrderedDict() _logger = get_logger(__name__) AsyncHTTPClient.configure(None, max_clients=100) #AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient", max_clients=100) def add_timer_routine(callback, callback_time): return PeriodicCallback(callback, callback_time) def del_timer_routine(timer): timer.stop() def route(pattern, method = HTTP_METHOD.GET): """
from pykafka import KafkaClient as PyKafkaClient from pykafka import BalancedConsumer from pykafka.partitioners import hashing_partitioner from tornado.gen import coroutine, Return from src.common.logutil import get_logger from src.common.configutil import get_config from src.common.reflectionutil import enum, import_resource, get_class from src.common.jsonutil import json2dict, dict2json from Queue import Queue, Empty from src.common.tornadoutil import add_timer_routine QUEUE_METHOD = enum(SUB='SUB', PUSH='PUSH') _config = get_config() _logger = get_logger(__name__) #_handler_dict = OrderedDict() _handler_dict = {} logger = get_logger(__name__) queue_consumer_threads = [] queue_consumer_jobs = [] def route(pattern, method = QUEUE_METHOD.SUB): """ Decorator to declare the routing rule of handler methods. """