Sha256: 3c0fcb5c24aa15deb4556108ef67db8d881ea001dda64edfa45891c16efb029f

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module Deimos
  module Utils
    # Overall functionality related to DB poller.
    module DbPoller
      # Begin the DB Poller process.
      # @return [void]
      def self.start!
        if Deimos.config.db_poller_objects.empty?
          raise('No pollers configured!')
        end

        pollers = Deimos.config.db_poller_objects.map do |poller_config|
          self.class_for_config(poller_config.mode).new(poller_config)
        end
        executor = Sigurd::Executor.new(pollers,
                                        sleep_seconds: 5,
                                        logger: Deimos.config.logger)
        signal_handler = Sigurd::SignalHandler.new(executor)
        signal_handler.run!
      end

      # @param config_name [Symbol]
      # @return [Class<Deimos::Utils::DbPoller>]
      def self.class_for_config(config_name)
        case config_name
        when :state_based
          Deimos::Utils::DbPoller::StateBased
        else
          Deimos::Utils::DbPoller::TimeBased
        end
      end

      PollStatus = Struct.new(:batches_processed, :batches_errored, :messages_processed) do

        # @return [Integer]
        def current_batch
          batches_processed + 1
        end

        # @return [String]
        def report
          "#{batches_processed} batches, #{batches_errored} errored batches, #{messages_processed} processed messages"
        end
      end
    end
  end
end

require 'deimos/utils/db_poller/base'
require 'deimos/utils/db_poller/time_based'
require 'deimos/utils/db_poller/state_based'

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
deimos-ruby-1.19.7 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.6 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.5 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.4 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.3 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.2 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.1 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.1.pre.beta1 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.0 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.beta2 lib/deimos/utils/db_poller.rb
deimos-ruby-1.19.beta1 lib/deimos/utils/db_poller.rb
deimos-ruby-1.18.2 lib/deimos/utils/db_poller.rb
deimos-ruby-1.18.1 lib/deimos/utils/db_poller.rb
deimos-ruby-1.18.0 lib/deimos/utils/db_poller.rb