[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/develop] Make how we keep track of successful reports more robust.



commit 056a24b84505d1d3f2602bc5ae55e8eea9edafba
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Mon Apr 29 13:42:01 2013 +0200

    Make how we keep track of successful reports more robust.
---
 ooni/reporter.py |   12 ++++++------
 ooni/tasks.py    |   19 +++++++++++++++++++
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/ooni/reporter.py b/ooni/reporter.py
index b04b46b..732d516 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -34,7 +34,7 @@ from ooni.utils.net import BodyReceiver, StringProducer, userAgents
 
 from ooni import config
 
-from ooni.tasks import ReportEntry, TaskTimedOut
+from ooni.tasks import ReportEntry, TaskTimedOut, ReportTracker
 
 class ReporterException(Exception):
     pass
@@ -429,13 +429,13 @@ class Report(object):
             been written or errbacks when no more reporters
         """
         all_written = defer.Deferred()
-        self._report_write_completed = []
+        report_tracker = ReportTracker(self.reporters)
 
         for reporter in self.reporters[:]:
-            def report_completed(result):
-                self._report_write_completed.append(result)
-                if len(self.reporters) == len(self._report_write_completed):
-                    all_written.callback(self._report_write_completed)
+            def report_completed(task):
+                report_tracker.completed()
+                if report_tracker.finished():
+                    all_written.callback(report_tracker)
 
             report_entry_task = ReportEntry(reporter, measurement)
             self.reportEntryManager.schedule(report_entry_task)
diff --git a/ooni/tasks.py b/ooni/tasks.py
index 59a908d..428fdbf 100644
--- a/ooni/tasks.py
+++ b/ooni/tasks.py
@@ -129,6 +129,25 @@ class Measurement(TaskWithTimeout):
         d = self.netTestMethod()
         return d
 
+class ReportTracker(object):
+    def __init__(self, reporters):
+        self.report_completed = 0
+        self.reporters = reporters
+
+    def finished(self):
+        """
+        Returns true if all the tasks are done. False if not.
+        """
+        if self.report_completed == len(self.reporters):
+            return True
+        return False
+
+    def completed(self):
+        """
+        Called when a new report is completed.
+        """
+        self.report_completed += 1
+
 class ReportEntry(TaskWithTimeout):
     timeout = config.advanced.reporting_timeout
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits