Class: Howler::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/howler/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



5
6
7
8
9
10
11
12
13
14
# File 'lib/howler/runner.rb', line 5

def initialize
  @options = {
    :concurrency => 30,
    :path => './config/environment.rb',
    :shutdown_timeout => 5
  }

  parse_options
  set_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/howler/runner.rb', line 3

def options
  @options
end

Instance Method Details

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/howler/runner.rb', line 16

def run
  require Howler::Config[:path]
  @manager = Howler::Manager.current

  begin
    @manager.run!
    sleep
  rescue Interrupt
    logger = Howler::Logger.new

    still_working = @manager.chewing.size
    shutdown_timeout = Howler::Config[:shutdown_timeout]

    logger.log do |log|
      log.info("INT - Stopping all workers")

      log.debug("INT - #{@manager.shutdown} workers were shutdown immediately.")
      log.debug("INT - #{still_working} workers still working.")

      log.info("INT - Waiting #{shutdown_timeout} seconds for workers to complete.") if still_working > 0
    end

    sleep(shutdown_timeout.to_i) if still_working > 0

    logger.info("INT - All workers have shut down - Exiting")
  end
end