]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/mirrors.py
Use Python's internal asyncio stuff instead of Tornado's
[ipfire.org.git] / src / backend / mirrors.py
index 647bbf2e95d33205db62129b8cb1043cee2d11d3..50ceb34d585611889c4b0911051c1dc2d0caabec 100644 (file)
@@ -8,7 +8,6 @@ import random
 import socket
 import time
 import ssl
-import tornado.gen
 import tornado.httpclient
 import tornado.iostream
 import tornado.netutil
@@ -37,11 +36,10 @@ class Mirrors(Object):
 
                return iter(mirrors)
 
-       @tornado.gen.coroutine
-       def check_all(self):
+       async def check_all(self):
                for mirror in self:
                        with self.db.transaction():
-                               yield mirror.check()
+                               await mirror.check()
 
        def get_for_download(self, filename, country_code=None):
                # Try to find a good mirror for this country first
@@ -197,17 +195,15 @@ class Mirror(Object):
        def disabled(self):
                return not self.enabled
 
-       @tornado.gen.coroutine
-       def check(self):
+       async def check(self):
                logging.debug("Running check for mirror %s" % self.hostname)
 
                self.db.execute("UPDATE mirrors SET address = %s WHERE id = %s",
                        self.address, self.id)
 
-               success = yield self.check_timestamp()
-
+               success = await self.check_timestamp()
                if success:
-                       yield self.check_filelist()
+                       await self.check_filelist()
 
        def check_state(self, last_update):
                logging.debug("Checking state of mirror %s" % self.id)
@@ -233,12 +229,11 @@ class Mirror(Object):
 
                self.set_state("UP")
 
-       @tornado.gen.coroutine
-       def check_timestamp(self):
+       async def check_timestamp(self):
                http = tornado.httpclient.AsyncHTTPClient()
 
                try:
-                       response = yield http.fetch(self.url + ".timestamp",
+                       response = await http.fetch(self.url + ".timestamp",
                                headers={ "Pragma" : "no-cache" })
                except tornado.httpclient.HTTPError as e:
                        logging.error("Error getting timestamp from %s: %s" % (self.hostname, e))
@@ -282,8 +277,7 @@ class Mirror(Object):
 
                return True
 
-       @tornado.gen.coroutine
-       def check_filelist(self):
+       async def check_filelist(self):
                # XXX need to remove data from disabled mirrors
                if not self.enabled:
                        return
@@ -291,7 +285,7 @@ class Mirror(Object):
                http = tornado.httpclient.AsyncHTTPClient()
 
                try:
-                       response = yield http.fetch(self.url + ".filelist",
+                       response = await http.fetch(self.url + ".filelist",
                                headers={ "Pragma" : "no-cache" })
                except tornado.httpclient.HTTPError as e:
                        logging.error("Error getting filelist from %s: %s" % (self.hostname, e))