]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/monitor.py
interfaces.py: whitespace
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / monitor.py
index 22de77132d1afb7496a53b22cb24152f52c2ad11..bdc66299f396acf9a204ee20d4a51312de0f5a76 100644 (file)
@@ -32,6 +32,11 @@ class IMonitor(Interface):
         operation code should stop creating new work, and attempt to stop any
         work already in progress."""
 
+    def raise_if_cancelled(self):
+        """Raise OperationCancelledError if the operation has been cancelled.
+        Operation code that has a robust error-handling path can simply call
+        this periodically."""
+
     def set_status(self, status):
         """Sets the Monitor's 'status' object to an arbitrary value.
         Different operations will store different sorts of status information
@@ -39,7 +44,8 @@ class IMonitor(Interface):
         this."""
 
     def get_status(self):
-        """Return the status object."""
+        """Return the status object. If the operation failed, this will be a
+        Failure instance."""
 
     def finish(self, status):
         """Call this when the operation is done, successful or not. The
@@ -69,6 +75,11 @@ class IMonitor(Interface):
 
     #   get_status() is useful too, but it is operation-specific
 
+
+class OperationCancelledError(Exception):
+    pass
+
+
 class Monitor:
     implements(IMonitor)
 
@@ -81,6 +92,10 @@ class Monitor:
     def is_cancelled(self):
         return self.cancelled
 
+    def raise_if_cancelled(self):
+        if self.cancelled:
+            raise OperationCancelledError()
+
     def is_finished(self):
         return self.finished