Sha256: 5bdd2ce663e47479de20236da95f0c0b91ad40bdccfa47ce2847b495926ec8af

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require "active_support"
require "active_support/all"
require "pulse-meter"

require "pulse_toolbox/sensor/initializer"

module PulseToolbox
  extend ActiveSupport::Autoload

  autoload :VERSION, 'pulse_toolbox/version'

  module Generators
    extend ActiveSupport::Autoload
    autoload :InstallGenerator
  end

  module Server
    extend ActiveSupport::Autoload
    autoload :Monitoring
  end

  module Sensor
    extend ActiveSupport::Autoload
    autoload :Manager
    module Mixins
      extend ActiveSupport::Autoload
      autoload :Iterators
    end
  end

  class << self
    @@pid = nil
    @@redis_config = {}

    def redis=(redis)
      PulseMeter.redis = redis
      @@pid = Process.pid
      @@redis_config = {
        :host => redis.client.host,
        :port => redis.client.port,
        :db => redis.client.db
      }
    end

    def redis
      reconnect if pid_changed
      PulseMeter.redis
    end

    def reconnect
      PulseMeter.redis = Redis.new(
        :host => @@redis_config[:host],
        :port => @@redis_config[:port],
        :db => @@redis_config[:db]
      )
    end

    def maybe_reconnect
      reconnect if pid_changed
    end

    def pid_changed
      @@pid && @@pid != Process.pid
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pulse-meter-rails-0.1.1 lib/pulse-meter-rails.rb
pulse-meter-rails-0.1.0 lib/pulse-meter-rails.rb