<commit_before>import databases
from motor import motor_asyncio
from arq import ArqRedis, create_pool
from arq.connections import RedisSettings
from sanic import Sanic

mongo_client: motor_asyncio.AsyncIOMotorClient = None
mongo_db: motor_asyncio.AsyncIOMotorDatabase = None
redis: ArqRedis = None


def create_app(config):
    # global
    app = Sanic(name=config['name'])
    app.config.from_object(config)

    app.pg_db = databases.Database(config['PSQL_URL'])

    app.listeners['after_server_start'].extend([setup_motor, setup_arq])

    app.listeners['before_server_stop'].extend([close_motor, close_arq])

    from .api.v1 import bpg
    app.register_blueprint(bpg)

    from .models import init_orm
    init_orm(app.pg_db)

    return app


async def setup_arq(app, loop):
    global redis
    redis = await create_pool(RedisSettings())


async def close_arq(app, loop):
    global redis
    redis.close()
    await redis.wait_closed()


async def setup_database(app, loop):
    await app._database.connect()


async def close_database(app, loop):
    await app._databases.disconnect()


async def setup_motor(app, loop):
    global mongo_client, mongo_db
    mongo_client = motor_asyncio.AsyncIOMotorClient(
        "mongodb://localhost:27017", io_loop=loop)
    mongo_db = mongo_client['test']


async def close_motor(app, loop):
    global mongo_client
    mongo_client.close()


# def make_arq(config):
#     global redis
#     redis = create_pool(RedisSettings())
#     return redis<commit_msg>fix init bug<commit_after>import databases
from motor import motor_asyncio
from arq import ArqRedis, create_pool
from arq.connections import RedisSettings
from sanic import Sanic

mongo_client: motor_asyncio.AsyncIOMotorClient = None
mongo_db: motor_asyncio.AsyncIOMotorDatabase = None
redis: ArqRedis = None
pg_db: databases.Database = None


def create_app(config):
    global pg_db
    app = Sanic(name=config.name)
    app.config.from_object(config)
    pg_db = databases.Database(app.config['PG_URL'])

    app.listeners['after_server_start'].extend(
        [setup_motor, setup_arq, setup_database])

    app.listeners['before_server_stop'].extend(
        [close_motor, close_arq, close_database])

    from .api.v1 import bpg
    app.register_blueprint(bpg)

    return app


async def setup_arq(app, loop):
    global redis
    redis = await create_pool(RedisSettings())


async def close_arq(app, loop):
    global redis
    redis.close()
    await redis.wait_closed()


async def setup_database(app, loop):
    global pg_db
    await pg_db.connect()


async def close_database(app, loop):
    global pg_db
    await pg_db.disconnect()


async def setup_motor(app, loop):
    global mongo_client, mongo_db
    mongo_client = motor_asyncio.AsyncIOMotorClient(
        "mongodb://localhost:27017", io_loop=loop)
    mongo_db = mongo_client['test']


async def close_motor(app, loop):
    global mongo_client
    mongo_client.close()


# def make_arq(config):
#     global redis
#     redis = create_pool(RedisSettings())
#     return redis
{'fraction_non_alphanumeric': 0.09328968903436989, 'fraction_numerical': 0.003927986906710311, 'mean_word_length': 4.179661016949153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686932', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1017, 'n_words': 228}