Class: Kryten::RemoteControl
- Inherits:
-
Object
- Object
- Kryten::RemoteControl
- Includes:
- DRbUndumped
- Defined in:
- lib/kryten/remote.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
readonly
Returns the value of attribute job.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(job) ⇒ RemoteControl
constructor
A new instance of RemoteControl.
- #shutdown ⇒ Object
- #start(name = nil) ⇒ Object
- #started ⇒ Object
- #status(name = nil) ⇒ Object
- #stop(name = nil) ⇒ Object
- #stopped ⇒ Object
- #worker(name) ⇒ Object
Constructor Details
#initialize(job) ⇒ RemoteControl
Returns a new instance of RemoteControl.
6 7 8 9 10 11 |
# File 'lib/kryten/remote.rb', line 6 def initialize(job) puts "Initialized #{job.name} server on pid #{Process.pid}" @job = job Signal.trap("TERM") { shutdown } Signal.trap("INT") { shutdown } end |
Instance Attribute Details
#job ⇒ Object (readonly)
Returns the value of attribute job.
5 6 7 |
# File 'lib/kryten/remote.rb', line 5 def job @job end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
5 6 7 |
# File 'lib/kryten/remote.rb', line 5 def workers @workers end |
Instance Method Details
#shutdown ⇒ Object
33 34 35 36 37 38 |
# File 'lib/kryten/remote.rb', line 33 def shutdown puts "Terminating #{job.name}" stop sleep 2 exit 0 end |
#start(name = nil) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/kryten/remote.rb', line 13 def start name=nil if name worker(name).start_work else puts "Starting #{job.name}" job.start_work end end |
#started ⇒ Object
56 57 58 |
# File 'lib/kryten/remote.rb', line 56 def started job.workers.select(&:started) end |
#status(name = nil) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/kryten/remote.rb', line 40 def status name=nil if name worker(name).status else job.status end end |
#stop(name = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kryten/remote.rb', line 22 def stop name=nil if name worker(name).stop_work else puts "Stopping #{job.name}" val = job.stop_work sleep job.timer return val end end |
#stopped ⇒ Object
60 61 62 |
# File 'lib/kryten/remote.rb', line 60 def stopped job.workers.reject(&:started) end |
#worker(name) ⇒ Object
48 49 50 |
# File 'lib/kryten/remote.rb', line 48 def worker name job.workers.detect {|w| w.name == name} end |