Sha256: 2dd5239bfd89e4aab5060cc9c5a9e0345ea1e6623376b93fc544fa0909870280

Contents?: true

Size: 1.43 KB

Versions: 9

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Deimos
  module Backends
    # Abstract class for all publish backends.
    class Base
      class << self
        # @param producer_class [Class<Deimos::Producer>]
        # @param messages [Array<Deimos::Message>]
        # @return [void]
        def publish(producer_class:, messages:)
          Deimos.config.logger.info(log_message(messages))
          execute(producer_class: producer_class, messages: messages)
        end

        # @param producer_class [Class<Deimos::Producer>]
        # @param messages [Array<Deimos::Message>]
        # @return [void]
        def execute(producer_class:, messages:)
          raise NotImplementedError
        end

      private

        def log_message(messages)
          log_message = {
            message: 'Publishing messages',
            topic: messages.first&.topic
          }

          case Deimos.config.payload_log
          when :keys
            log_message.merge!(
              payload_keys: messages.map(&:key)
            )
          when :count
            log_message.merge!(
              payloads_count: messages.count
            )
          else
            log_message.merge!(
              payloads: messages.map do |message|
                {
                  payload: message.payload,
                  key: message.key
                }
              end
            )
          end

          log_message
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
deimos-ruby-1.22.3 lib/deimos/backends/base.rb
deimos-ruby-1.22.2 lib/deimos/backends/base.rb
deimos-ruby-1.22.1 lib/deimos/backends/base.rb
deimos-ruby-1.22 lib/deimos/backends/base.rb
deimos-ruby-1.20.1 lib/deimos/backends/base.rb
deimos-ruby-1.20.0 lib/deimos/backends/base.rb
deimos-ruby-1.19.7 lib/deimos/backends/base.rb
deimos-ruby-1.19.6 lib/deimos/backends/base.rb
deimos-ruby-1.19.5 lib/deimos/backends/base.rb