Skip to content
Snippets Groups Projects
worker.py 736 B
Newer Older
  • Learn to ignore specific revisions
  • import aiohttp
    
    
    from funkwhale_network import crawler
    from funkwhale_network import db
    from funkwhale_network import settings
    
    Georg Krause's avatar
    Georg Krause committed
    from aiohttp import ClientSession
    from arq import cron
    
    Georg Krause's avatar
    Georg Krause committed
    
    async def poll(ctx, domain):
    
        session: ClientSession = ctx["session"]
    
    Georg Krause's avatar
    Georg Krause committed
        pool = await db.get_pool(settings.DB_DSN)
        async with pool as conn:
            return await crawler.check(conn=conn, session=session, domain=domain)
    
    
    Georg Krause's avatar
    Georg Krause committed
    async def update_all(ctx):
        pool = await db.get_pool(settings.DB_DSN)
        for check in await db.get_latest_check_by_domain(pool):
            await poll(ctx, check["domain"])
    
    Georg Krause's avatar
    Georg Krause committed
    class WorkerSettings:
    
        cron_jobs = [cron(update_all, minute=None)]
    
        max_concurrent_tasks = 20
        shutdown_delay = 5
        timeout_seconds = 15