Sha256: ce06982e9176e11f57246c80c0a1fad1e01f4fd3de155a6a3f7fdfa760482e4f

Contents?: true

Size: 947 Bytes

Versions: 1

Compression:

Stored size: 947 Bytes

Contents

module SnowmanIO
  # Processor initiated by Scheduler, executes check and notifies
  # Scheduler about the result of the check.
  class Processor
    include Celluloid

    def initialize(scheduler)
      @scheduler = scheduler
    end

    # TODO: logging can be extracted in some kind of middleware
    def process(check)
      begin
        SnowmanIO.logger.info("Processing check #{check.human}, started at #{Time.now}")
        result = check.new.perform
      rescue Exception => e
        result = result_from_exception(check, e)
        raise
      ensure
        SnowmanIO.logger.info("Processing check #{check.human}, finished at #{Time.now}")
        @scheduler.processor_done(current_actor, result)
      end
    end

    private

    def result_from_exception(check, e)
      message = "Check #{check.human} was interruppted by exception: #{e.class}: #{e.message}"
      CheckResult.new(check, "exception", message)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snowman-io-0.0.4 lib/snowman-io/processor.rb