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
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
# get_status() is useful too, but it is operation-specific
+
+class OperationCancelledError(Exception):
+ pass
+
+
class Monitor:
implements(IMonitor)
def is_cancelled(self):
return self.cancelled
+ def raise_if_cancelled(self):
+ if self.cancelled:
+ raise OperationCancelledError()
+
def is_finished(self):
return self.finished