From: Michael Tremer Date: Tue, 21 Jan 2025 10:24:14 +0000 (+0000) Subject: mirrors: Run all checks concurrently X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3fdf2e120760836db011cd4942598632dcb65a4;p=ipfire.org.git mirrors: Run all checks concurrently Signed-off-by: Michael Tremer --- diff --git a/src/backend/mirrors.py b/src/backend/mirrors.py index 26958553..6e6a4b15 100644 --- a/src/backend/mirrors.py +++ b/src/backend/mirrors.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import asyncio import datetime import logging import iso3166 @@ -39,9 +40,11 @@ class Mirrors(Object): return iter(mirrors) async def check_all(self): - for mirror in self: - with self.db.transaction(): - await mirror.check() + async with asyncio.TaskGroup() as tg: + for mirror in self: + tg.create_task( + mirror.check(), + ) def get_for_download(self, filename, country_code=None): # Try to find a good mirror for this country first @@ -205,12 +208,13 @@ class Mirror(Object): async def check(self): logging.debug("Running check for mirror %s" % self.hostname) - self.db.execute("UPDATE mirrors SET address = %s WHERE id = %s", - await self.resolve(), self.id) + with self.db.transaction(): + self.db.execute("UPDATE mirrors SET address = %s WHERE id = %s", + await self.resolve(), self.id) - success = await self.check_timestamp() - if success: - await self.check_filelist() + success = await self.check_timestamp() + if success: + await self.check_filelist() def check_state(self, last_update): logging.debug("Checking state of mirror %s" % self.id)