Esempio n. 1
0
    def stop(self):
        """
        Stop the consumer and return offset of last processed message.  This
        cancels all outstanding operations.  Also, if the deferred returned
        by `start` hasn't been called, it is called with a tuple consisting
        of the last processed offset and the last committed offset.

        :raises: :exc:`RestopError` if the :class:`Consumer` is not running.
        """
        if self._start_d is None:
            raise RestopError("Stop called on non-running consumer")

        self._stopping = True
        # Keep track of state for debugging
        self._state = '[stopping]'
        # Are we waiting for a request to come back?
        if self._request_d:
            self._request_d.cancel()
        # Are we working our way through a block of messages?
        if self._msg_block_d:
            # Need to add a cancel handler...
            _msg_block_d, self._msg_block_d = self._msg_block_d, None
            _msg_block_d.addErrback(lambda fail: fail.trap(CancelledError))
            _msg_block_d.cancel()
        # Are we waiting for the processor to complete?
        if self._processor_d:
            self._processor_d.cancel()
        # Are we waiting to retry a request?
        if self._retry_call:
            self._retry_call.cancel()
        # Are we waiting on a commit request?
        if self._commit_ds:
            while self._commit_ds:
                d = self._commit_ds.pop()
                d.cancel()
        if self._commit_req:
            self._commit_req.cancel()
        # Are we waiting to retry a commit?
        if self._commit_call:
            self._commit_call.cancel()
        # Do we have an auto-commit looping call?
        if self._commit_looper is not None:
            self._commit_looper.stop()
        # Done stopping
        self._stopping = False
        # Keep track of state for debugging
        self._state = '[stopped]'

        # Clear and possibly callback our start() Deferred
        self._start_d, d = None, self._start_d
        if not d.called:
            d.callback(
                (self._last_processed_offset, self._last_committed_offset))

        # Return tuple with the offset of the message we last processed,
        # and the offset we last committed
        return (self._last_processed_offset, self._last_committed_offset)
Esempio n. 2
0
    def stop(self):
        """
        Stop the consumer and return offset of last processed message.  This
        cancels all outstanding operations.  Also, if the deferred returned
        by `start` hasn't been called, it is called with a tuple consisting
        of the last processed offset and the last committed offset.

        :raises: :exc:`RestopError` if the :class:`Consumer` is not running.
        """
        if self._start_d is None:
            raise RestopError("Stop called on non-running consumer")

        self._stopping = True
        # Keep track of state for debugging
        self._state = '[stopping]'
        # Are we waiting for a request to come back?
        if self._request_d:
            self._request_d.cancel()
        # Are we working our way through a block of messages?
        if self._msg_block_d:
            # Need to add a cancel handler...
            _msg_block_d, self._msg_block_d = self._msg_block_d, None
            _msg_block_d.addErrback(lambda fail: fail.trap(CancelledError))
            _msg_block_d.cancel()
        # Are we waiting for the processor to complete?
        if self._processor_d:
            self._processor_d.cancel()
        # Are we waiting to retry a request?
        if self._retry_call:
            self._retry_call.cancel()
        # Are we waiting on a commit request?
        if self._commit_ds:
            while self._commit_ds:
                d = self._commit_ds.pop()
                d.cancel()
        if self._commit_req:
            self._commit_req.cancel()
        # Are we waiting to retry a commit?
        if self._commit_call:
            self._commit_call.cancel()
        # Do we have an auto-commit looping call?
        if self._commit_looper is not None:
            self._commit_looper.stop()
        # Done stopping
        self._stopping = False
        # Keep track of state for debugging
        self._state = '[stopped]'

        # Clear and possibly callback our start() Deferred
        self._start_d, d = None, self._start_d
        if not d.called:
            d.callback((self._last_processed_offset,
                        self._last_committed_offset))

        # Return the offset of the message we last processed
        return self._last_processed_offset
Esempio n. 3
0
 def handle_config_error(fail):
     fail.trap(UnknownConfigError)
     sys.stderr.write("\nConfiguration error:\n{}\n\n".format(
         fail.value))
     reactor.stop()
     return
 def failureNoSuch(fail):
     fail.trap(pb.NoSuchMethod)
     self.compare(fail.traceback, "Traceback unavailable\n")
     return 42000
 def failureDeferredSecurity(fail):
     fail.trap(SecurityError)
     self.failIf(isinstance(fail.type, str))
     self.failUnless(isinstance(fail.value, fail.type))
     return 43000
 def failureJelly(fail):
     fail.trap(JellyError)
     self.failIf(isinstance(fail.type, str))
     self.failUnless(isinstance(fail.value, fail.type))
     return 43
Esempio n. 7
0
 def failureNoSuch(fail):
     fail.trap(pb.NoSuchMethod)
     self.compare(fail.traceback, "Traceback unavailable\n")
     return 42000
Esempio n. 8
0
 def failureDeferredSecurity(fail):
     fail.trap(SecurityError)
     self.failIf(isinstance(fail.type, str))
     self.failUnless(isinstance(fail.value, fail.type))
     return 43000
Esempio n. 9
0
 def failureJelly(fail):
     fail.trap(JellyError)
     self.failIf(isinstance(fail.type, str))
     self.failUnless(isinstance(fail.value, fail.type))
     return 43
Esempio n. 10
0
 def handle_config_error(fail):
     fail.trap(UnknownConfigError)
     sys.stderr.write("\nConfiguration error:\n{}\n\n".format(fail.value))
     reactor.stop()
     return