Sha256: 8bb0cb0d2268935d3c65cbe5764227e9e2e2c758dfa87bebb2d02c1b263df3af

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'thor'

module HttpHealthCheck
  module Utils
    module Karafka
      # returns a list of consumer groups configured for current process
      #
      # @param karafka_app descendant of Karafka::App
      def self.consumer_groups(karafka_app, program_name: $PROGRAM_NAME, argv: ARGV) # rubocop:disable Metrics/AbcSize
        all_groups = karafka_app.consumer_groups.map(&:id)
        client_id_prefix = karafka_app.config.client_id.gsub('-', '_') + '_'

        return all_groups if program_name.split('/').last != 'karafka'
        return all_groups if argv[0] != 'server'

        parsed_option = Thor::Options.new(
          consumer_groups: Thor::Option.new(:consumer_groups, type: :array, default: nil, aliases: :g)
        ).parse(argv).fetch('consumer_groups', []).first.to_s
        return all_groups if parsed_option == ''

        groups_from_option = parsed_option.split(' ').map { |g| client_id_prefix + g } & all_groups
        groups_from_option.empty? ? all_groups : groups_from_option
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
http_health_check-0.4.1 lib/http_health_check/utils/karafka.rb
http_health_check-0.4.0 lib/http_health_check/utils/karafka.rb