def main(): """Run a consumer. Two environment variables are expected: * CONFIG_URI: A PasteDeploy URI pointing at the configuration for the application. * QUEUE: The name of the queue to consume (currently one of "events" or "errors"). """ config_uri = os.environ["CONFIG_URI"] config = paste.deploy.loadwsgi.appconfig(config_uri) logging.config.fileConfig(config["__file__"]) queue_name = os.environ["QUEUE"] queue = events.queue.make_queue(queue_name, config) messages = queue.consume() topic_name = config["topic." + queue_name] region = config["aws.region"] kinesis = boto.kinesis.connect_to_region(region) stats_client = events.stats.make_stats_client(config) kinesis_batch_consumer = KinesisBatchConsumer(kinesis, topic_name, stats_client) batcher = Batcher(kinesis_batch_consumer) consume_items_in_batches(messages, batcher)
def test_consume_empty(self): queue = self._make_queue(key=0x5ca1ab1e) iterator = queue.consume() with mock.patch("time.sleep") as mock_sleep: item = iterator.next() self.assertTrue(mock_sleep.called) self.assertEqual(item, None)
def main(): """Run a consumer. Two environment variables are expected: * CONFIG_URI: A PasteDeploy URI pointing at the configuration for the application. * QUEUE: The name of the queue to consume (currently one of "events" or "errors"). """ config_uri = os.environ["CONFIG_URI"] config = paste.deploy.loadwsgi.appconfig(config_uri) logging.config.fileConfig(config["__file__"]) queue_name = os.environ["QUEUE"] queue = events.queue.make_queue(queue_name, config) messages = queue.consume() topic_name = config["topic." + queue_name] region = config["aws.region"] kinesis = boto.kinesis.connect_to_region(region) stats_client = events.stats.make_stats_client(config) kinesis_batch_consumer = KinesisBatchConsumer( kinesis, topic_name, stats_client) batcher = Batcher(kinesis_batch_consumer) consume_items_in_batches(messages, batcher)
def test_consume_with_items(self): queue = self._make_queue(key=0x5ca1ab1e) queue.put("example") iterator = queue.consume() item = iterator.next() self.assertEqual(item, "example")