Class: Woodhouse::Process

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

Overview

TODO: take arguments. Also consider using thor.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyw = {}) ⇒ Process

Returns a new instance of Process.



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

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

Class Method Details

.instanceObject

Returns the current global Woodhouse process instance, if it is running.



14
15
16
# File 'lib/woodhouse/process.rb', line 14

def self.instance
  @instance
end

.register_instance(instance) ⇒ Object



9
10
11
# File 'lib/woodhouse/process.rb', line 9

def self.register_instance(instance)
  @instance = instance
end

Instance Method Details

#executeObject



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

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

  Woodhouse::Watchdog.start

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

#shutdownObject



42
43
44
45
46
# File 'lib/woodhouse/process.rb', line 42

def shutdown
  puts "Shutting down."
  @server.async.shutdown
  @server.wait(:shutdown)
end