Class: DIY::WorkerKeeper
- Inherits:
-
Object
- Object
- DIY::WorkerKeeper
- Defined in:
- lib/diy/worker_keeper.rb
Overview
创建DRb服务
Instance Attribute Summary collapse
-
#running ⇒ Object
Returns the value of attribute running.
Instance Method Summary collapse
-
#initialize(worker, uri) {|_self| ... } ⇒ WorkerKeeper
constructor
A new instance of WorkerKeeper.
- #run ⇒ Object
- #stop ⇒ Object
- #use_timeridconv ⇒ Object
Constructor Details
#initialize(worker, uri) {|_self| ... } ⇒ WorkerKeeper
Returns a new instance of WorkerKeeper.
8 9 10 11 12 13 14 |
# File 'lib/diy/worker_keeper.rb', line 8 def initialize(worker, uri) @worker = worker @uri = uri @running = false @over = false yield self if block_given? end |
Instance Attribute Details
#running ⇒ Object
Returns the value of attribute running.
15 16 17 |
# File 'lib/diy/worker_keeper.rb', line 15 def running @running end |
Instance Method Details
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/diy/worker_keeper.rb', line 22 def run Thread.abort_on_exception = true DIY::Logger.info "serving at #{@uri}" DRb.start_service(@uri, @worker) @running = true @over = false trap("INT") { @running = false } while @running sleep 0.5 end DIY::Logger.info "bye..." @worker.stop DRb.stop_service @over = true end |
#stop ⇒ Object
38 39 40 41 |
# File 'lib/diy/worker_keeper.rb', line 38 def stop @running = false Utils.wait_until { @over } end |
#use_timeridconv ⇒ Object
17 18 19 20 |
# File 'lib/diy/worker_keeper.rb', line 17 def use_timeridconv require 'drb/timeridconv' DRb.install_id_conv DRb::TimerIdConv.new end |