def test_wait_before_retry(self): must_stop = mock.Mock() stdout_consumer = ( ConsumerRegister.get_consumer('Stdout')['consumer_cls']({})) stdout_consumer._wait_before_retry(must_stop) must_stop.wait.assert_called_once_with( timeout=stdout_consumer.retry_delay)
def test_wait_before_retry(self, time_mock): must_stop = threading.Event() stdout_consumer = ( ConsumerRegister.get_consumer('Stdout')['consumer_cls']({})) stdout_consumer._wait_before_retry(must_stop) time_mock.sleep.assert_called_with(1) self.assertEquals(time_mock.sleep.call_count, stdout_consumer.retry_delay)
def launch(self): """Launch sauna daemon Start consumers and producer threads. """ signal.signal(signal.SIGTERM, self.term_handler) signal.signal(signal.SIGINT, self.term_handler) consumers_threads = [] for consumer_data in self.consumers: consumer_name = consumer_data['type'] consumer_info = ConsumerRegister.get_consumer(consumer_name) if not consumer_info: print('Plugin {} does not exist'.format(consumer_name)) exit(1) try: consumer = consumer_info['consumer_cls'](consumer_data) except DependencyError as e: print(str(e)) self.term_handler() exit(1) if isinstance(consumer, QueuedConsumer): consumer_queue = queue.Queue() self._consumers_queues.append(consumer_queue) else: consumer_queue = None consumer_thread = threading.Thread( name='consumer_{}'.format(consumer_name), target=consumer.run, args=(self.must_stop, consumer_queue) ) consumer_thread.start() consumers_threads.append(consumer_thread) logging.debug( 'Running consumer {}'.format(consumer_name) ) producer = threading.Thread( name='producer', target=self.run_producer ) producer.start() producer.join() self.term_handler() for consumer_thread in consumers_threads: consumer_thread.join() logging.debug('Exited main thread')
def launch(self): """Launch sauna daemon Start consumers and producer threads. """ signal.signal(signal.SIGTERM, self.term_handler) signal.signal(signal.SIGINT, self.term_handler) consumers_threads = [] for consumer_data in self.consumers: consumer_name = consumer_data['type'] consumer_info = ConsumerRegister.get_consumer(consumer_name) if not consumer_info: print('Plugin {} does not exist'.format(consumer_name)) sys.exit(1) try: consumer = consumer_info['consumer_cls'](consumer_data) except DependencyError as e: print(str(e)) self.term_handler() sys.exit(1) if isinstance(consumer, QueuedConsumer): consumer_queue = queue.Queue() self._consumers_queues.append(consumer_queue) else: consumer_queue = None consumer_thread = threading.Thread( name='consumer_{}'.format(consumer_name), target=consumer.run, args=(self.must_stop, consumer_queue) ) consumer_thread.start() consumers_threads.append(consumer_thread) logger.debug( 'Running consumer {}'.format(consumer_name) ) producer = threading.Thread( name='producer', target=self.run_producer ) producer.start() producer.join() self.term_handler() for consumer_thread in consumers_threads: consumer_thread.join() logger.debug('Exited main thread')
def launch(self): # Start producer and consumer threads producer = threading.Thread(name='producer', target=self.run_producer) producer.start() consumers_threads = [] for consumer_name, consumer_config in self.config['consumers'].items(): consumer_info = ConsumerRegister.get_consumer(consumer_name) if not consumer_info: print('Plugin {} does not exist'.format(consumer_name)) exit(1) try: consumer = consumer_info['consumer_cls'](consumer_config) except DependencyError as e: print(str(e)) exit(1) if isinstance(consumer, QueuedConsumer): consumer_queue = queue.Queue() self._consumers_queues.append(consumer_queue) else: consumer_queue = None consumer_thread = threading.Thread( name='consumer_{}'.format(consumer_name), target=consumer.run, args=(self.must_stop, consumer_queue)) consumer_thread.start() consumers_threads.append(consumer_thread) logging.debug('Running {} with {}'.format(consumer_name, consumer_config)) signal.signal(signal.SIGTERM, self.term_handler) signal.signal(signal.SIGINT, self.term_handler) producer.join() self.term_handler() for consumer_thread in consumers_threads: consumer_thread.join() logging.debug('Exited main thread')
def test_get_consumer(self): stdout_consumer = ConsumerRegister.get_consumer('Stdout') self.assert_(issubclass(stdout_consumer['consumer_cls'], base.Consumer)) must_be_none = ConsumerRegister.get_consumer('Unknown') self.assertIsNone(must_be_none)
def test_get_consumer(self): stdout_consumer = ConsumerRegister.get_consumer('Stdout') self.assert_(issubclass(stdout_consumer['consumer_cls'], base.Consumer)) must_be_none = ConsumerRegister.get_consumer('Unknown') self.assertIsNone(must_be_none)