def reset(self): debug('Resetting active actors') for actor in values(self.registry): if actor.consumer: ignore_errors(self.connection, actor.consumer.cancel) actor.connection = self.connection self._start_actor_consumer(actor)
def kill(self, actor_id): if actor_id not in self.registry: raise Actor.Next() else: actor = self.registry.pop(actor_id) if actor.consumer and actor.consumer.channel: ignore_errors(self.connection, actor.consumer.cancel)
def shutdown(self, c): """Shutdown task consumer.""" if c.task_consumer: self.stop(c) debug('Closing consumer channel...') ignore_errors(c, c.task_consumer.close) c.task_consumer = None
def stop(self, c): channels = set() for consumer in self.consumers or []: ignore_errors(c.connection, consumer.cancel) if consumer.channel: channels.add(consumer.channel) for channel in channels: ignore_errors(c.connection, channel.close)
def _close(self, c, cancel_consumers=True): channels = set() for consumer in self.consumers or []: if cancel_consumers: ignore_errors(c.connection, consumer.cancel) if consumer.channel: channels.add(consumer.channel) for channel in channels: ignore_errors(c.connection, channel.close)
def stop(self, c): if c.event_dispatcher: # remember changes from remote control commands: self.groups = c.event_dispatcher.groups # close custom connection if c.event_dispatcher.connection: ignore_errors(c, c.event_dispatcher.connection.close) ignore_errors(c, c.event_dispatcher.close) c.event_dispatcher = None
def _shutdown(self, cancel=True, close=True, clear=True): try: for actor in values(self.registry): if actor and actor.consumer: if cancel: ignore_errors(self.connection, actor.consumer.cancel) if close and actor.consumer.channel: ignore_errors(self.connection, actor.consumer.channel.close) finally: if clear: self.registry.clear()
def test_ignore_errors(self): l = MyKombuConsumer(self.buffer.put, timer=self.timer, app=self.app) l.connection_errors = (AttributeError, KeyError, ) l.channel_errors = (SyntaxError, ) ignore_errors(l, Mock(side_effect=AttributeError('foo'))) ignore_errors(l, Mock(side_effect=KeyError('foo'))) ignore_errors(l, Mock(side_effect=SyntaxError('foo'))) with self.assertRaises(IndexError): ignore_errors(l, Mock(side_effect=IndexError('foo')))
def test_ignore_errors(self): c = self.NoopConsumer() c.connection_errors = (AttributeError, KeyError,) c.channel_errors = (SyntaxError,) ignore_errors(c, Mock(side_effect=AttributeError('foo'))) ignore_errors(c, Mock(side_effect=KeyError('foo'))) ignore_errors(c, Mock(side_effect=SyntaxError('foo'))) with pytest.raises(IndexError): ignore_errors(c, Mock(side_effect=IndexError('foo')))
def test_ignored(self): connection = Mock() connection.channel_errors = (KeyError,) connection.connection_errors = (KeyError,) with ignore_errors(connection): raise KeyError() def raising(): raise KeyError() ignore_errors(connection, raising) connection.channel_errors = connection.connection_errors = () with self.assertRaises(KeyError): with ignore_errors(connection): raise KeyError()
def test_ignore_errors(): connection = Mock() connection.channel_errors = (KeyError,) connection.connection_errors = (KeyError,) with ignore_errors(connection): raise KeyError() def raising(): raise KeyError() ignore_errors(connection, raising) connection.channel_errors = connection.connection_errors = () with pytest.raises(KeyError): with ignore_errors(connection): raise KeyError()
def shutdown(self, c): # We must set self.connection to None here, so # that the green pidbox thread exits. connection, c.connection = c.connection, None if connection: ignore_errors(connection, connection.close)
def stop(self, c): if c.task_consumer: debug('Cancelling task consumer...') ignore_errors(c, c.task_consumer.cancel)
def shutdown(self, c): self.on_stop() if self.consumer: debug('Canceling broadcast consumer...') ignore_errors(c, self.consumer.cancel) self.stop(self.c)
def _close_channel(self, c): if self.node and self.node.channel: ignore_errors(c, self.node.channel.close)
def shutdown(self, c): self.on_stop() if self.consumer: debug('Cancelling broadcast consumer...') ignore_errors(c, self.consumer.cancel) self.stop(self.c)
def stop(self, c): for consumer in self.consumers or []: ignore_errors(c.connection, consumer.cancel)
def shutdown(self, c): self.stop(c) for consumer in self.consumers or []: if consumer.channel: ignore_errors(c.connection, consumer.channel.close)
def shutdown(self, c): if c.task_consumer: self.stop(c) debug("Closing consumer channel...") ignore_errors(c, c.task_consumer.close) c.task_consumer = None
def shutdown(self, c): if c.task_consumer: self.stop(c) debug('Closing consumer channel...') ignore_errors(c, c.task_consumer.close) c.task_consumer = None
def stop(self, c): if c.event_dispatcher: ignore_errors(c, c.event_dispatcher.close) c.event_dispatcher = None
def stop(self, c): if c.event_dispatcher: if c.event_dispatcher.connection: ignore_errors(c, c.event_dispatcher.connection.close) ignore_errors(c, c.event_dispatcher.close) c.event_dispatcher = None