Sha256: 522e57b422b7ca0e6fda5b8da7415a7a4e34b03c18dddad622a5b034b69a197a

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module Sidekiq
  module Cluster
    module Monitors
      SLEEP_DELAY = 5
      LOGGING_PERIOD = 30

      class Base
        attr_accessor :pool, :thread

        def initialize(pool)
          self.pool = pool
          @last_logged_at = Time.now.to_i
        end

        def start
          self.thread = Thread.new { self.monitor }
          self
        end

        def join
          thread.join if thread
        end

        def monitor
          raise 'Abstract method'
        end

        def log_periodically(msg, &block)
          t = Time.now.to_i
          if t - @last_logged_at > LOGGING_PERIOD
            pool.cli.info(msg) if msg
            Array(block.call).each do |result|
              pool.cli.info(result)
            end if block
            @last_logged_at = t
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-cluster-0.1.2 lib/sidekiq/cluster/monitors/base.rb