Sha256: cf9d54d1cfb5a14833f7d1d9f31f28154b62190b32a030033af07f24c63d39bd

Contents?: true

Size: 1.19 KB

Versions: 7

Compression:

Stored size: 1.19 KB

Contents

require 'snowman-io/loop/check_processor'

module SnowmanIO
  module Loop
    class ChecksPerform
      def self.perform
        Check.each do |check|
          result = CheckProcessor.new(check).process
          send_mail = false
          check.last_run_at = DateTime.now
          if result
            puts "Check for #{check.metric.name} triggered"
            unless check.triggered
              send_mail = true
            end
            check.triggered = true
            check.last_status = Check::STATUS_FAILED
          else
            check.last_status = Check::STATUS_OK
          end
          check.save!

          if send_mail
            SnowMailer.check_triggered(
              check,
              check.last_run_at,
              Setting.get(SnowmanIO::BASE_URL_KEY),
              check.user.email,
              true
            ).deliver_now

            check.user.followers.each do |user|
              SnowMailer.check_triggered(
                check,
                check.last_run_at,
                Setting.get(SnowmanIO::BASE_URL_KEY),
                user.email,
                false
              ).deliver_now
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

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