Sha256: 82f81dee08ffe68fe326aff6ecefbb774140fb3dc87ff5746896200ec9544682

Contents?: true

Size: 753 Bytes

Versions: 3

Compression:

Stored size: 753 Bytes

Contents

require 'eventmachine'

class Nagios::RunnerAsync < Nagios::Runner

  # synchrony check, for manual call
  # do not run in EM
  def self.check(params = {})
    raise "cant check sync in running EM" if EM.reactor_running?

    result = nil
    EM.run do
      self.new(params) do |res|
        begin
          result = res
        ensure
          EM.stop
        end
      end
    end

    result
  end

protected

  def run
    if @ancestor == Nagios::Check
      # to thread pool
      EM.defer do
        script = @klass.new(@params, &@callback)
        script.run
      end

    elsif @ancestor == Nagios::CheckEM
      script = @klass.new(@params, &@callback)
      script.run

    else
      raise "unknown klass #{@klass_name}"
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nagios_helper-0.2.2 lib/nagios/runner_async.rb
nagios_helper-0.2.1 lib/nagios/runner_async.rb
nagios_helper-0.2 lib/nagios/runner_async.rb