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

Fix decorator issues

parent 101969f3
No related branches found
No related tags found
No related merge requests found
import aiopg
import psycopg2
from funkwhale_network import settings
async def get_pool(db_dsn):
return await aiopg.create_pool(db_dsn)
......@@ -67,8 +69,8 @@ TABLES = [("domains", create_domains_table), ("checks", create_checks_table)]
def dict_cursor(func):
async def inner(conn, *args, **kwargs):
async with conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) as cursor:
return await func(cursor, *args, **kwargs)
cursor = await conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
return await func(cursor, *args, **kwargs)
return inner
......@@ -78,6 +80,8 @@ async def get_latest_check_by_domain(cursor):
sql = """
SELECT DISTINCT on (domain) domain, * FROM checks INNER JOIN domains ON checks.domain = domains.name WHERE private = %s AND domains.blocked = false ORDER BY domain, time DESC
"""
conn = await aiopg.connect(settings.DB_DSN)
cursor = await conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
await cursor.execute(sql, [False])
return list(await cursor.fetchall())
......
......@@ -20,8 +20,11 @@ async def update_all(ctx):
for check in await db.get_latest_check_by_domain(pool):
await poll(ctx, check["domain"])
async def startup(ctx):
ctx["session"] = ClientSession()
class WorkerSettings:
on_startup = startup
cron_jobs = [cron(update_all, minute=None)]
max_concurrent_tasks = 20
shutdown_delay = 5
......
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