class SnowmanIO::Loop::CheckProcessor

Public Class Methods

new(check) click to toggle source
# File lib/snowman-io/loop/check_processor.rb, line 4
def initialize(check)
  @check  = check
  @metric = check.metric
end

Public Instance Methods

process() click to toggle source
# File lib/snowman-io/loop/check_processor.rb, line 9
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