#!/usr/bin/python
+import asyncio
import datetime
import logging
import iso3166
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
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)