Class: Woodhouse::Process
- Inherits:
-
Object
- Object
- Woodhouse::Process
- Defined in:
- lib/woodhouse/process.rb
Overview
TODO: take arguments. Also consider using thor.
Class Method Summary collapse
-
.instance ⇒ Object
Returns the current global Woodhouse process instance, if it is running.
- .register_instance(instance) ⇒ Object
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(keyw = {}) ⇒ Process
constructor
A new instance of Process.
- #shutdown ⇒ Object
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
.instance ⇒ Object
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
#execute ⇒ Object
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 |
#shutdown ⇒ Object
42 43 44 45 46 |
# File 'lib/woodhouse/process.rb', line 42 def shutdown puts "Shutting down." @server.async.shutdown @server.wait(:shutdown) end |