Sha256: 6b76ee77f3e5c730fed2fbdd8c0a1665ad0d7a802b757b7a9af9ff7f786d48b6

Contents?: true

Size: 844 Bytes

Versions: 9

Compression:

Stored size: 844 Bytes

Contents

module SnowmanIO
  module Loop
    class CheckProcessor
      def initialize(check)
        @check  = check
        @metric = check.metric
      end

      def process
        if @check.template == Check::TEMPLATE_LAST_VALUE_LIMIT
          @check.cmp_fn.call(@metric.last_value, @check.value)

        elsif @check.template == Check::TEMPLATE_PREV_DAY_DATAPOINTS_LIMIT
          # use aggregation for prev day
          at = Time.now.beginning_of_day - 1.day
          if @metric.created_at < at # require full gather day
            count = @metric.aggregations.where("precision" => "daily", "at" => at).first.try(&:count).to_i
            @check.cmp_fn.call(count, @check.value)
          else
            false
          end

        else
          raise "Unknown check template: #{@check.template}"
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/loop/check_processor.rb
snowman-io-0.5.0 lib/snowman-io/loop/check_processor.rb
snowman-io-0.4.0 lib/snowman-io/loop/check_processor.rb
snowman-io-0.3.1 lib/snowman-io/loop/check_processor.rb
snowman-io-0.3.0 lib/snowman-io/loop/check_processor.rb
snowman-io-0.2.0 lib/snowman-io/loop/check_processor.rb
snowman-io-0.1.0 lib/snowman-io/loop/check_processor.rb
snowman-io-0.0.6 lib/snowman-io/loop/check_processor.rb
snowman-io-0.0.5 lib/snowman-io/loop/check_processor.rb