]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish.py: handle asynchronous checker results.
authorBrian Warner <warner@allmydata.com>
Wed, 31 Oct 2007 00:00:37 +0000 (17:00 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 31 Oct 2007 00:00:37 +0000 (17:00 -0700)
Thanks to robk for pointing out that Nevow will accept a Deferred almost
everywhere. In this case, we just pass a Deferred into ctx.fillSlots(). One
quirk: nevow doesn't evaluate all rows of the table in parallel: using a slow
Deferred in a slot in one row seems to stall the next row until that one has
fired, probably to simplify the flattening of the HTML.

src/allmydata/webish.py

index ecde7f67828ee034396e24dcdeb300b2a95eb948..d7e07299122201dbe6e91de758479cdb2a08a9ca 100644 (file)
@@ -232,24 +232,31 @@ class Directory(rend.Page):
         except KeyError:
             checker = None
         if checker:
-            checker_results = checker.checker_results_for(target.get_verifier())
-            recent_results = reversed(checker_results[-5:])
-            if IFileNode.providedBy(target):
-                results = ("[" +
-                           ", ".join(["%d/%d" % (found, needed)
-                                      for (when,
-                                           (needed, total, found, sharemap))
-                                      in recent_results]) +
-                           "]")
-            elif IDirectoryNode.providedBy(target):
-                results = ("[" +
-                           "".join([{True:"+",False:"-"}[res]
-                                    for (when, res) in recent_results]) +
-                           "]")
-            else:
-                results = "%d results" % len(checker_results)
+            d = defer.maybeDeferred(checker.checker_results_for,
+                                    target.get_verifier())
+            def _got(checker_results):
+                recent_results = reversed(checker_results[-5:])
+                if IFileNode.providedBy(target):
+                    results = ("[" +
+                               ", ".join(["%d/%d" % (found, needed)
+                                          for (when,
+                                               (needed, total, found, sharemap))
+                                          in recent_results]) +
+                               "]")
+                elif IDirectoryNode.providedBy(target):
+                    results = ("[" +
+                               "".join([{True:"+",False:"-"}[res]
+                                        for (when, res) in recent_results]) +
+                               "]")
+                else:
+                    results = "%d results" % len(checker_results)
+                return results
+            d.addCallback(_got)
+            results = d
         else:
             results = "--"
+        # TODO: include a link to see more results, including timestamps
+        # TODO: use a sparkline
         ctx.fillSlots("checker_results", results)
 
         return ctx.tag