def sync(self): """Sync the in-memory list of OOPS with the external OOPS source.""" if not self.channel: return # Send ourselves a message: when we receive this, we've processed all # oopses created before sync() was invoked. message = amqp.Message(self.AMQP_SENTINEL) # Match what oops publishing does message.properties["delivery_mode"] = 2 # Publish the message via a new channel (otherwise rabbit # shortcircuits it straight back to us, apparently). connection = connect() try: channel = connection.channel() try: channel.basic_publish(message, config.error_reports.error_exchange, config.error_reports.error_queue_key) finally: channel.close() finally: connection.close() receiver = oops_amqp.Receiver(self.oops_config, connect, self.queue_name) receiver.sentinel = self.AMQP_SENTINEL try: receiver.run_forever() finally: # Ensure we leave the queue ready to roll, or later calls to # sync() will fail. self.setUpQueue()
def sync(self): """Sync the in-memory list of OOPS with the external OOPS source.""" if not self.channel: return # Send ourselves a message: when we receive this, we've processed all # oopses created before sync() was invoked. message = amqp.Message(self.AMQP_SENTINEL) # Match what oops publishing does message.properties["delivery_mode"] = 2 # Publish the message via a new channel (otherwise rabbit # shortcircuits it straight back to us, apparently). connection = connect() try: channel = connection.channel() try: channel.basic_publish( message, config.error_reports.error_exchange, config.error_reports.error_queue_key ) finally: channel.close() finally: connection.close() receiver = oops_amqp.Receiver(self.oops_config, connect, self.queue_name) receiver.sentinel = self.AMQP_SENTINEL try: receiver.run_forever() finally: # Ensure we leave the queue ready to roll, or later calls to # sync() will fail. self.setUpQueue()
def setUp(self): super(CaptureOops, self).setUp() self.oopses = [] self.oops_ids = set() self.useFixture(ZopeEventHandlerFixture(self._recordOops)) try: self.connection = connect() except MessagingUnavailable: self.channel = None else: self.addCleanup(self.connection.close) self.channel = self.connection.channel() self.addCleanup(self.channel.close) self.oops_config = oops.Config() self.oops_config.publishers.append(self._add_oops) self.setUpQueue()