Sha256: e56f37f76c88b402d9354197f8f9dff7512887acea0b74fc2ea4542a1cab3321

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module Metricize
  module SharedMethods

    def establish_redis_connection
      log_message "metricize_version=#{VERSION} connecting to Redis at #{@queue_host}:#{@queue_port}", :info
      with_error_handling do
        @redis = Redis.connect(:host => @queue_host, :port => @queue_port)
        @redis.ping
      end
    end

    private

    def initialize_redis(options)
      @queue_host  = options[:queue_host] || '127.0.0.1'
      @queue_port  = options[:queue_port] || 6379
      @queue_name  = options[:queue_name] || 'metricize_queue'
      establish_redis_connection
    end

    def establish_logger(options)
      @logger = options[:logger] || Logger.new(STDOUT)
    end

    def log_message(message, level = :debug)
      message = "[#{self.class} #{Process.pid}] " + message
      @logger.send(level.to_sym, message)
    end

    def time_delta_ms(start_time)
      (((Time.now - start_time) * 100000.0).round) / 100.0
    end

    def round(value, num_places)
      factor = 10.0**num_places
      ((value * factor).round) / factor
    end

    def with_error_handling
      yield
    rescue StandardError => e
      log_message %Q(#{e.class}:#{e.message}\n#{e.backtrace.join("\n")}), :error
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metricize-0.5.7 lib/metricize/shared.rb
metricize-0.5.6 lib/metricize/shared.rb
metricize-0.5.4 lib/metricize/shared.rb
metricize-0.5.3 lib/metricize/shared.rb
metricize-0.5.2 lib/metricize/shared.rb
metricize-0.5.1 lib/metricize/shared.rb