Exemplo n.º 1
0
    def __init__(self, **kwargs):
        if not kwargs.get('servers', False):
            raise NameError, 'servers syntax'

        if not self._conn:
            self._conn = asyncmemcache.ClientPool(
                kwargs['servers'],
                maxclients=int(kwargs.get('maxclients', 100))
            )
            # 如果有数据库连接,交需要持久化的数据写入数据库
            database = config.get('database')

            if database:
                MemcacheModel._meta.database = database
                is_sync = False

                def sync():
                    global is_sync
                    if is_sync:
                        return

                    is_sync = True
                    if False == (yield gen.Task(MemcacheModel.table_exists)):
                        yield gen.Task(MemcacheModel.create_table)
                    else:
                        # 从数据表中读取数据,并写入缓存
                        data = yield gen.Task(MemcacheModel.select().execute)
                        for v in data:
                            self.set(v.key, Json.decode(v.value), 0)
               
                if not database.get_conn()._get_connection():
                    database.on_connect(sync)
                    #database.connect()
                else:
                    sync()
Exemplo n.º 2
0
    def __init__(self, **kwargs):
        if not kwargs.get('servers', False):
            raise NameError, 'servers syntax'

        if not self._conn:
            self._conn = asyncmemcache.ClientPool(
                kwargs['servers'],
                maxclients=int(kwargs.get('maxclients', 100)))
            # 如果有数据库连接,交需要持久化的数据写入数据库
            database = config.get('database')

            if database:
                MemcacheModel._meta.database = database
                is_sync = False

                def sync():
                    global is_sync
                    if is_sync:
                        return

                    is_sync = True
                    if False == (yield gen.Task(MemcacheModel.table_exists)):
                        yield gen.Task(MemcacheModel.create_table)
                    else:
                        # 从数据表中读取数据,并写入缓存
                        data = yield gen.Task(MemcacheModel.select().execute)
                        for v in data:
                            self.set(v.key, Json.decode(v.value), 0)

                if not database.get_conn()._get_connection():
                    database.on_connect(sync)
                    #database.connect()
                else:
                    sync()
Exemplo n.º 3
0
 class Meta:
     database = config.get('database')
Exemplo n.º 4
0
    'ContentData',
    'table_prefix',
]
import uuid
import xcat
from xcat import utils
from xcat import mopee, config
from tornado import gen
from app.models import AsyncModel, User

# 表前缀
table_prefix = 'cms_'

# 加载缓存
cache = False
cache_cfg = config.get('cache', False)
cache_storage = cache_cfg.get('storage', 'Mongod')
if cache_cfg and hasattr(xcat.cache, cache_storage):
    Cache = getattr(xcat.cache, cache_storage)
    #print cache_cfg.get('config')
    cache = Cache(**cache_cfg.get('config', {}))


class Table(AsyncModel):
    """内容表列表"""

    # 模型定义缓存
    _model_caches = {}

    class Meta:
        db_table = '%s%s' % (table_prefix, 'table')
Exemplo n.º 5
0
    from psycopg2cffi import compat
    compat.register()
elif psycopg2_impl == 'psycopg2ct':
    from psycopg2ct import compat
    compat.register()

from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from xcat import config
from xcat.web import Application
from config import settings


# 设置运行模式
settings['run_mode'] = options.model
config.load(settings)

# 连接数据库,长连接
config.get('database').connect()

# uimodules
from app import uimodules
config.set('ui_modules', uimodules)

if __name__ == '__main__':
    from app.handlers import *
    application = Application(**config.get())
    http_server = HTTPServer(application)
    http_server.listen(options.port)
    IOLoop.instance().start()
Exemplo n.º 6
0
    'ContentData',
    'table_prefix',
]
import uuid
import xcat
from xcat import utils
from xcat import mopee, config
from tornado import gen
from app.models import AsyncModel, User

# 表前缀
table_prefix = 'cms_'

# 加载缓存 
cache = False
cache_cfg = config.get('cache', False)
cache_storage = cache_cfg.get('storage', 'Mongod')
if cache_cfg and hasattr(xcat.cache, cache_storage):
    Cache = getattr(xcat.cache, cache_storage)
    #print cache_cfg.get('config')
    cache = Cache(**cache_cfg.get('config', {}))


class Table(AsyncModel):
    """内容表列表"""

    # 模型定义缓存
    _model_caches = {}

    class Meta:
        db_table = '%s%s' % (table_prefix, 'table')
Exemplo n.º 7
0
if psycopg2_impl == 'psycopg2cffi':
    from psycopg2cffi import compat
    compat.register()
elif psycopg2_impl == 'psycopg2ct':
    from psycopg2ct import compat
    compat.register()

from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from xcat import config
from xcat.web import Application
from config import settings

# 设置运行模式
settings['run_mode'] = options.model
config.load(settings)

# 连接数据库,长连接
config.get('database').connect()

# uimodules
from app import uimodules
config.set('ui_modules', uimodules)

if __name__ == '__main__':
    from app.handlers import *
    application = Application(**config.get())
    http_server = HTTPServer(application)
    http_server.listen(options.port)
    IOLoop.instance().start()