Sha256: 85c54be3c4ef0b830ab409ba0db7481c5061bc2163fc477a644b30a3ee815d24

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module PgEventstore
  module CommandHandlers
    class SubscriptionFeederCommands
      # @param config_name [Symbol]
      # @param subscription_feeder [PgEventstore::SubscriptionFeeder]
      def initialize(config_name, subscription_feeder)
        @config_name = config_name
        @subscription_feeder = subscription_feeder
      end

      # Look up commands for the given SubscriptionFeeder and execute them
      # @return [void]
      def process
        commands.each do |command|
          command.exec_cmd(@subscription_feeder)
          queries.delete(command.id)
        end
      end

      private

      # @return [Array<PgEventstore::SubscriptionFeederCommands::Base>]
      def commands
        commands = queries.find_commands(@subscription_feeder.id)
        ping_cmd = commands.find do |cmd|
          cmd.name == 'Ping'
        end
        return commands unless ping_cmd

        # "Ping" command should go in prio
        [ping_cmd, *(commands - [ping_cmd])]
      end

      # @return [PgEventstore::SubscriptionsSetCommandQueries]
      def queries
        SubscriptionsSetCommandQueries.new(connection)
      end

      # @return [PgEventstore::Connection]
      def connection
        PgEventstore.connection(@config_name)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pg_eventstore-1.9.0 lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb
pg_eventstore-1.8.0 lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb
pg_eventstore-1.7.0 lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb
pg_eventstore-1.6.0 lib/pg_eventstore/subscriptions/command_handlers/subscription_feeder_commands.rb