chiark / gitweb /
Periodically refresh pirate info
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 13:35:15 +0000 (14:35 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 17 May 2009 13:35:15 +0000 (14:35 +0100)
yoweb-scrape

index 03607451167a1d831c77f8137ad525e8783388ec..a943f3cb5a4ccd7951d930486d121c07864948ed 100755 (executable)
@@ -89,8 +89,9 @@ class Fetcher:
                        ages.append(age)
                return ages
 
-       def need_wait(self, now):
+       def need_wait(self, now, imaginary=[]):
                ages = self._cache_scan(now)
+               ages += imaginary
                ages.sort()
                debug('Fetcher   ages ' + `ages`)
                min_age = 1
@@ -417,8 +418,23 @@ class PirateAboard:
                pa.pi = None
 
        def pirate_info(pa):
-               if not pa.pi and not fetcher.need_wait(time.time()):
-                       pa.pi = PirateInfo(pa.name, 3600)
+               now = time.time()
+               if pa.pi:
+                       age = now - pa.pi_fetched
+                       guide = random.randint(120,240)
+                       if age <= guide:
+                               return pa.pi
+                       debug('PirateAboard refresh %d > %d  %s' % (
+                               age, guide, pa.name))
+                       imaginary = [2,6]
+               else:
+                       imaginary = [1]
+               wait = fetcher.need_wait(now, imaginary)
+               if wait:
+                       debug('PirateAboard fetcher not ready %d' % wait)
+                       return pa.pi
+               pa.pi = PirateInfo(pa.name, 600)
+               pa.pi_fetched = now
                return pa.pi
 
 class ChatLogTracker: