Class: Woodhouse::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/woodhouse/process.rb

Overview

TODO: take arguments. Also consider using thor.

Instance Method Summary collapse

Constructor Details

#initialize(keyw = {}) ⇒ Process

Returns a new instance of Process.



4
5
6
# File 'lib/woodhouse/process.rb', line 4

def initialize(keyw = {})
  @server = keyw[:server] || build_default_server(keyw)
end

Instance Method Details

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/woodhouse/process.rb', line 8

def execute
  # Borrowed this from sidekiq. https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/cli.rb
  trap "INT" do
    Thread.main.raise Interrupt
  end

  trap "TERM" do
    Thread.main.raise Interrupt
  end

  begin
    @server.start!
    puts "Woodhouse serving as of #{Time.now}. Ctrl-C to stop."
    @server.wait(:shutdown) 
  rescue Interrupt
    puts "Shutting down."
    @server.shutdown!
    @server.wait(:shutdown)
  ensure
    @server.terminate
    exit
  end
end