Class: DeepTest::Distributed::RemoteWorkerServer
- Inherits:
-
Object
- Object
- DeepTest::Distributed::RemoteWorkerServer
- Includes:
- DRb::DRbUndumped
- Defined in:
- lib/deep_test/distributed/remote_worker_server.rb
Constant Summary collapse
- MERCY_KILLING_GRACE_PERIOD =
10 * 60
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .running_server_count ⇒ Object
- .start(address, base_path, workers, options, grace_period = MERCY_KILLING_GRACE_PERIOD) ⇒ Object
- .stop_all ⇒ Object
- .warlock ⇒ Object
Instance Method Summary collapse
-
#drbserver=(drbserver) ⇒ Object
These methods allow us to proxy the Server through the NAT.
-
#initialize(base_path, workers, options) ⇒ RemoteWorkerServer
constructor
A new instance of RemoteWorkerServer.
- #launch_mercy_killer(grace_period) ⇒ Object
- #load_files(files) ⇒ Object
- #start_all ⇒ Object
- #stop_all ⇒ Object
- #take_work ⇒ Object
- #workers_started? ⇒ Boolean
- #write_result(res) ⇒ Object
Constructor Details
#initialize(base_path, workers, options) ⇒ RemoteWorkerServer
Returns a new instance of RemoteWorkerServer.
11 12 13 14 15 16 17 18 19 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 11 def initialize(base_path, workers, ) @base_path = base_path @workers = workers @options = @resolver = FilenameResolver.new(@base_path) @options.libs.each { |l| $: << @resolver.resolve(l) } @options.requires.each { |r| require r } end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
9 10 11 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 9 def uri @uri end |
Class Method Details
.running_server_count ⇒ Object
62 63 64 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 62 def self.running_server_count @warlock.demon_count if @warlock end |
.start(address, base_path, workers, options, grace_period = MERCY_KILLING_GRACE_PERIOD) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 70 def self.start(address, base_path, workers, , grace_period = MERCY_KILLING_GRACE_PERIOD) innie, outie = IO.pipe warlock.start("RemoteWorkerServer") do innie.close server = new(base_path, workers, ) # this is half the magic that lets us work through the NAT DRb.start_service("drbfire://#{address}:0", server, DRbFire::ROLE => DRbFire::SERVER, DRbFire::DELEGATE => DRbBindAllTCPSocket) DeepTest.logger.info "RemoteWorkerServer started at #{DRb.uri}" server.uri = DRb.uri outie.write DRb.uri outie.close server.launch_mercy_killer(grace_period) DRb.thread.join end outie.close uri = innie.gets innie.close DRbObject.new_with_uri(uri) end |
.stop_all ⇒ Object
66 67 68 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 66 def self.stop_all @warlock.stop_all if @warlock end |
Instance Method Details
#drbserver=(drbserver) ⇒ Object
These methods allow us to proxy the Server through the NAT
101 102 103 104 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 101 def drbserver=(drbserver) DeepTest.logger.debug "Setting the Server remote reference to: #{drbserver.inspect}" @drbserver = drbserver end |
#launch_mercy_killer(grace_period) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 21 def launch_mercy_killer(grace_period) Thread.new do sleep grace_period exit(0) unless workers_started? end end |
#load_files(files) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 28 def load_files(files) @options.new_listener_list.before_remote_load_files Dir.chdir @base_path resolver = FilenameResolver.new(@base_path) files.each do |file| load resolver.resolve(file) end rescue Exception => e puts e. pp e.backtrace raise end |
#start_all ⇒ Object
43 44 45 46 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 43 def start_all @workers_started = true @workers.start_all(self) end |
#stop_all ⇒ Object
48 49 50 51 52 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 48 def stop_all Thread.new do @workers.stop_all end end |
#take_work ⇒ Object
105 106 107 108 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 105 def take_work DeepTest.logger.debug "Remote worker server proxying 'take_work' back to Server" @drbserver.take_work end |
#workers_started? ⇒ Boolean
54 55 56 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 54 def workers_started? @workers_started end |
#write_result(res) ⇒ Object
109 110 111 |
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 109 def write_result(res) @drbserver.write_result res end |