def consumer_entry(): cmd_args = parse_arguments() worker_type = cmd_args.worker_type assert worker_type in WORKER_CLASSES, \ 'Unsupported worker type: `%s`' % worker_type worker_cls = WORKER_CLASSES[worker_type] worker_cls.patch() consumer = load_entry_point(cmd_args.entry_point) assert inspect.isclass(consumer), 'consumer must be a class' from arkham.consumer.consumer import ArkhamConsumer, ArkhamConsumerRunner assert issubclass(consumer, ArkhamConsumer), 'consumer class must be subclass of ArkhamConsumer' has_kwargs = bool(inspect.getargspec(consumer.consume.im_func).keywords) if not has_kwargs: ArkhamWarning.warn('consume function should have **kwargs.') runner = ArkhamConsumerRunner( worker_cls, consumer, find_config(cmd_args.config_path, cmd_args.entry_point), cmd_args.consumer_name ) runner.start()
def initialize(self): import gevent.monkey gevent.monkey.patch_all() # using select.poll in gevent context may cause 100% cpu usage, # but not reproduced in pika 0.10.1-dev0 # import select # gevent.monkey.remove_item(select, 'poll') import gevent.pool pool_size = self.consumer.prefetch_count if pool_size is None: ArkhamWarning.warn( "worker_class set to `gevent` but prefetch_count is None, " "pool_size set to %s" % self.DEFAULT_POOL_SIZE ) pool_size = self.DEFAULT_POOL_SIZE self.pool = gevent.pool.Pool(pool_size) import gevent gevent.spawn(self.loop_watcher).start()
def initialize(self): import gevent.pool pool_size = self.consumer.prefetch_count if pool_size is None: ArkhamWarning.warn('worker_class set to `gevent` but prefetch_count is None, ' 'pool_size set to %s' % self.DEFAULT_POOL_SIZE) pool_size = self.DEFAULT_POOL_SIZE self.pool = gevent.pool.Pool(pool_size) import gevent gevent.spawn(self.loop_watcher).start()
def consumer_entry(): cmd_args = parse_arguments() consumer = load_entry_point(cmd_args.entry_point) assert inspect.isclass(consumer), "consumer must be a class" assert issubclass(consumer, ArkhamConsumer), "consumer class must be subclass of ArkhamConsumer" has_kwargs = bool(inspect.getargspec(consumer.consume.im_func).keywords) if not has_kwargs: ArkhamWarning.warn("consume function should have **kwargs.") runner = _ArkhamConsumerRunner( consumer, find_config(cmd_args.config_path, cmd_args.entry_point), cmd_args.consumer_name ) runner.start()