Ejemplo n.º 1
0
def start_app(port):
    app = web.Application(middlewares=[db_middleware, error_middleware])

    app['db'] = DBAsyncClient()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.ensure_future(run_migrations()))
    setup_routes(app)
    web.run_app(app, port=port)
Ejemplo n.º 2
0
def start_app(port):
    app = web.Application()
    logging.basicConfig(
        format='%(asctime)s %(name)s %(levelname)s %(message)s',
        level=settings.LOG_LEVEL
    )

    app['db'] = DBAsyncClient(**DB_CONFIG)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(app['db'].create_connection())
    Tortoise.init(app['db'])
    loop.run_until_complete(run_migrations())
    setup_routes(app)
    web.run_app(app, port=port)
async def app(loop, tortoise, request):
    app = web.Application()
    setup_routes(app)
    app['db'] = tortoise
    await tortoise.create_connection()

    transaction = tortoise.in_transaction()
    await transaction.start()
    Tortoise._set_global_connection(transaction)

    def fin():
        loop.run_until_complete(transaction.rollback())
        loop.run_until_complete(tortoise.close())

    request.addfinalizer(fin)
    return app
Ejemplo n.º 4
0
import pathlib
from aiohttp import web
from binstar_client.utils import load_config
from app.router import setup_routes
from app.db import *
import aiohttp_jinja2
import jinja2
import aiohttp_session
import base64
from cryptography import fernet
from aiohttp_session.redis_storage import RedisStorage
import aioredis
import asyncio

app = web.Application()
conf = load_config(str(pathlib.Path('config/aio-market.yaml')))
app['config'] = conf
app.on_startup.append(init_mysql)
app.on_cleanup.append(close_mysql)
app.router.add_static('/static', path=str('static'), name='static')
aiohttp_jinja2.setup(app, loader=jinja2.PackageLoader('app', 'templates'))

fernet_key = fernet.Fernet.generate_key()
secret_key = base64.urlsafe_b64decode(fernet_key)
redis = asyncio.get_event_loop().run_until_complete(
    aioredis.create_pool(('localhost', 6379)))
aiohttp_session.setup(app, RedisStorage(redis, max_age=30 * 60))
setup_routes(app)
web.run_app(app, host='localhost', port=80)