Class: KingKong::Runner
- Inherits:
-
Object
- Object
- KingKong::Runner
- Includes:
- Logging
- Defined in:
- lib/kingkong/runner.rb,
lib/kingkong/runner.rb
Overview
Configure multiple pingers to run
Defined Under Namespace
Modules: DSL
Class Method Summary collapse
-
.configure(&block) ⇒ Object
Shortcut for creating a new class and configuring it.
-
.run(&block) ⇒ Object
Shortcut for configuring and starting a KingKong runner.
Instance Method Summary collapse
-
#configure(&block) ⇒ Object
Open up the configuration DSL for this puppy.
-
#on_pong(&block) ⇒ Object
Configure the processor that we use to report pings.
-
#ping(name, &block) ⇒ Object
Array of pingers that we’re running.
-
#process(ping, name) ⇒ Object
We use this method to pass our pings through a processor.
-
#start ⇒ Object
Start all of the pingers given the configurations.
-
#stop ⇒ Object
Stop all of the pingers.
Methods included from Logging
Class Method Details
.configure(&block) ⇒ Object
Shortcut for creating a new class and configuring it
45 46 47 |
# File 'lib/kingkong/runner.rb', line 45 def self.configure(&block) new.configure(&block) end |
.run(&block) ⇒ Object
Shortcut for configuring and starting a KingKong runner
50 51 52 53 54 55 56 |
# File 'lib/kingkong/runner.rb', line 50 def self.run(&block) ensure_running_reactor { runner = configure(&block) runner.start } runner # For chaining end |
Instance Method Details
#configure(&block) ⇒ Object
Open up the configuration DSL for this puppy
39 40 41 42 |
# File 'lib/kingkong/runner.rb', line 39 def configure(&block) block.arity > 1 ? block.call(self) : instance_eval(&block) self end |
#on_pong(&block) ⇒ Object
Configure the processor that we use to report pings
24 25 26 |
# File 'lib/kingkong/runner.rb', line 24 def on_pong(&block) @processor = block end |
#ping(name, &block) ⇒ Object
Array of pingers that we’re running
9 10 11 12 13 14 15 16 |
# File 'lib/kingkong/runner.rb', line 9 def ping(name, &block) DSL::Pinger.new(&block).completed do |pinger| pinger.on_ping do |ping| process ping, name end pingers << pinger end end |
#process(ping, name) ⇒ Object
We use this method to pass our pings through a processor
19 20 21 |
# File 'lib/kingkong/runner.rb', line 19 def process(ping, name) @processor.call(ping,name) if @processor end |
#start ⇒ Object
Start all of the pingers given the configurations
29 30 31 |
# File 'lib/kingkong/runner.rb', line 29 def start start_pingers end |
#stop ⇒ Object
Stop all of the pingers
34 35 36 |
# File 'lib/kingkong/runner.rb', line 34 def stop pingers.each(&:stop) end |