Sha256: abebcdb65e5a6db91220894ebab81c8b2928daa81037e071ebe8dc555e1e20cd

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

# This Karafka component is a Pro component under a commercial license.
# This Karafka component is NOT licensed under LGPL.
#
# All of the commercial components are present in the lib/karafka/pro directory of this
# repository and their usage requires commercial license agreement.
#
# Karafka has also commercial-friendly license, commercial support and commercial components.
#
# By sending a pull request to the pro components, you are agreeing to transfer the copyright of
# your code to Maciej Mensfeld.

module Karafka
  module Pro
    module ActiveJob
      # Contract for validating the options that can be altered with `#karafka_options` per job
      # class that works with Pro features.
      class JobOptionsContract < Contracts::Base
        configure do |config|
          config.error_messages = YAML.safe_load(
            File.read(
              File.join(Karafka.gem_root, 'config', 'locales', 'errors.yml')
            )
          ).fetch('en').fetch('validations').fetch('job_options')
        end

        optional(:producer) { |val| val.nil? || val.respond_to?(:call) }
        optional(:partitioner) { |val| val.respond_to?(:call) }
        optional(:partition_key_type) { |val| %i[key partition_key partition].include?(val) }

        # Whether this is a legit scheduled messages topic will be validated during the first
        # dispatch, so we do not repeat validations here
        optional(:scheduled_messages_topic) do |val|
          (val.is_a?(String) || val.is_a?(Symbol)) &&
            ::Karafka::Contracts::TOPIC_REGEXP.match?(val.to_s)
        end

        optional(:dispatch_method) do |val|
          %i[
            produce_async
            produce_sync
          ].include?(val)
        end

        optional(:dispatch_many_method) do |val|
          %i[
            produce_many_async
            produce_many_sync
          ].include?(val)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
karafka-2.4.14 lib/karafka/pro/active_job/job_options_contract.rb
karafka-2.4.13 lib/karafka/pro/active_job/job_options_contract.rb
karafka-2.4.12 lib/karafka/pro/active_job/job_options_contract.rb