コード例 #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
from datetime import datetime
from playhouse.migrate import *
from peewee import ProgrammingError

from sanicms import load_config

config = load_config()

db = PostgresqlDatabase(**config['DB_CONFIG'])
migrator = PostgresqlMigrator(db)

logger = logging.getLogger('sanic')


class MigrationRecord(Model):
    id = PrimaryKeyField()
    table = CharField()
    version = CharField()
    author = CharField()
    create_time = DateTimeField(verbose_name='创建时间', default=datetime.utcnow())

    class Meta:
        table_name = 'migration_record'
        database = db


def info(version=None, author=None, datetime=None):
コード例 #2
0
from sanic.response import json, text, HTTPResponse
from sanic.exceptions import RequestTimeout, NotFound
from aiohttp import ClientSession

from sanicms import load_config
from sanicms.db import ConnectionPool
from sanicms.client import Client
from sanicms.utils import *
from sanicms.loggers import AioReporter
from sanicms.openapi import blueprint as openapi_blueprint

with open(os.path.join(os.path.dirname(__file__), 'logging.yml'), 'r') as f:
    logging.config.dictConfig(yaml.load(f))

app = Sanic(__name__, error_handler=CustomHandler())
app.config = load_config()
app.blueprint(openapi_blueprint)


@app.listener('before_server_start')
async def before_srver_start(app, loop):
    queue = asyncio.Queue()
    app.queue = queue
    loop.create_task(consume(queue, app.config['ZIPKIN_SERVER']))
    reporter = AioReporter(queue=queue)
    tracer = BasicTracer(recorder=reporter)
    tracer.register_required_propagators()
    opentracing.tracer = tracer
    app.db = await ConnectionPool(loop=loop).init(app.config['DB_CONFIG'])