Skip to content
Snippets Groups Projects
Verified Commit 0c9f3d1d authored by Georg Krause's avatar Georg Krause
Browse files

Use a common pool for a running task

parent a58bf555
No related branches found
No related tags found
No related merge requests found
Pipeline #26557 failed with stages
in 5 minutes and 22 seconds
......@@ -162,6 +162,8 @@ async def poll(domains):
"""
from . import crawler
await DB.create_pool()
if not domains:
async with DB() as db:
domains_db = await db.get_all_domains()
......@@ -170,7 +172,10 @@ async def poll(domains):
kwargs = crawler.get_session_kwargs()
async with aiohttp.ClientSession(**kwargs) as session:
tasks = [launch_domain_poll(session, d) for d in domains]
return await asyncio.wait(tasks)
await asyncio.wait(tasks)
await DB.close_pool()
return
NOOP = object()
......@@ -298,16 +303,6 @@ def aggregate_crawl_results(domains_info):
@click.option("--check", is_flag=True)
def start(*, check, verbose):
arq.worker.run_worker(WorkerSettings)
# TODO launch runner
# worker = arq.worker.import_string("funkwhale_network.worker", "Worker")
# logging.config.dictConfig(worker.logging_config(verbose))
if check:
pass
# exit(worker.check_health())
else:
pass
# arq.RunWorkerProcess("funkwhale_network.worker", "Worker", burst=False)
def main():
......
......@@ -5,6 +5,8 @@ from funkwhale_network import settings
class DB:
pool: aiopg.Pool
def __init__(self):
self.TABLES = [
("domains", self.create_domains_table),
......@@ -12,15 +14,23 @@ class DB:
]
async def __aenter__(self):
await self.create_pool()
await DB.create_pool()
return self
async def __aexit__(self, *excinfo):
self.pool.close()
await self.pool.wait_closed()
async def __aexit__(self, exc_type, exc, tb):
return
@classmethod
async def close_pool(cls):
cls.pool.close()
await cls.pool.wait_closed()
async def create_pool(self):
self.pool = await aiopg.create_pool(settings.DB_DSN)
@classmethod
async def create_pool(cls):
try:
cls.pool
except AttributeError:
cls.pool = await aiopg.create_pool(settings.DB_DSN)
def get_cursor(self):
yield self.pool.cursor()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment