Class: DeepTest::Distributed::RemoteWorkerServer

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, options)
  @base_path = base_path
  @workers = workers
  @options = options
  
  @resolver = FilenameResolver.new(@base_path)
  @options.libs.each { |l| $: << @resolver.resolve(l) }
  @options.requires.each { |r| require r }
end

Instance Attribute Details

#uriObject

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_countObject



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, options, grace_period = MERCY_KILLING_GRACE_PERIOD)
  innie, outie = IO.pipe

  warlock.start("RemoteWorkerServer") do
    innie.close

    server = new(base_path, workers, options)
    
    # 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_allObject



66
67
68
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 66

def self.stop_all
  @warlock.stop_all if @warlock
end

.warlockObject



58
59
60
# File 'lib/deep_test/distributed/remote_worker_server.rb', line 58

def self.warlock
  @warlock ||= DeepTest::Warlock.new
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.message
  pp e.backtrace
  raise
end

#start_allObject



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_allObject



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_workObject



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

Returns:

  • (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