]> git.ipfire.org Git - ipfire.org.git/commitdiff
mirrors: Run all checks concurrently
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Jan 2025 10:24:14 +0000 (10:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 21 Jan 2025 10:24:14 +0000 (10:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/mirrors.py

index 26958553f016e1d914e837160fe5d70c268615c9..6e6a4b1535e450e6352b52372dd909b6e053f31a 100644 (file)
@@ -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)