Sha256: 5719abd2b16eb4e862d5aa6ce7b4ac200c6ec4bef21ba697fa800c827b30cbf4

Contents?: true

Size: 1.3 KB

Versions: 27

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Karafka
  module Schemas
    # Schema for validating correctness of the server cli command options
    # We validate some basics + the list of consumer_groups on which we want to use, to make
    # sure that all of them are defined, plus that a pidfile does not exist
    ServerCliOptions = Dry::Validation.Schema do
      configure do
        option :consumer_groups

        def self.messages
          super.merge(
            en: {
              errors: {
                consumer_groups_inclusion: 'Unknown consumer group.',
                pid_existence: 'Pidfile already exists.'
              }
            }
          )
        end
      end

      optional(:pid).filled(:str?)
      optional(:daemon).filled(:bool?)
      optional(:consumer_groups).filled(:array?)

      validate(consumer_groups_inclusion: :consumer_groups) do |consumer_groups|
        # If there were no consumer_groups declared in the server cli, it means that we will
        # run all of them and no need to validate them here at all
        if consumer_groups.nil?
          true
        else
          (consumer_groups - Karafka::Routing::Builder.instance.map(&:name)).empty?
        end
      end

      validate(pid_existence: :pid) do |pid|
        pid ? !File.exist?(pid) : true
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
karafka-1.2.13 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.12 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.11 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.10 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.9 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.8 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.7 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.6 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.5 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.4 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.3 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.2 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.1 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.0 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.0.beta4 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.0.beta3 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.0.beta2 lib/karafka/schemas/server_cli_options.rb
karafka-1.2.0.beta1 lib/karafka/schemas/server_cli_options.rb
karafka-1.1.2 lib/karafka/schemas/server_cli_options.rb
karafka-1.1.1 lib/karafka/schemas/server_cli_options.rb