Class: Specjour::Manager
Instance Attribute Summary collapse
Instance Method Summary
collapse
#hostname, #ip_from_hostname
Constructor Details
#initialize(options = {}) ⇒ Manager
Returns a new instance of Manager.
11
12
13
14
15
16
|
# File 'lib/specjour/manager.rb', line 11
def initialize(options = {})
@worker_size = options[:worker_size]
@batch_size = options[:batch_size]
@registered_projects = options[:registered_projects]
@worker_pids = []
end
|
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def batch_size
@batch_size
end
|
#bonjour_service ⇒ Object
Returns the value of attribute bonjour_service.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def bonjour_service
@bonjour_service
end
|
#dispatcher_uri ⇒ Object
Returns the value of attribute dispatcher_uri.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def dispatcher_uri
@dispatcher_uri
end
|
#project_name ⇒ Object
Returns the value of attribute project_name.
8
9
10
|
# File 'lib/specjour/manager.rb', line 8
def project_name
@project_name
end
|
#registered_projects ⇒ Object
Returns the value of attribute registered_projects.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def registered_projects
@registered_projects
end
|
#specs_to_run ⇒ Object
Returns the value of attribute specs_to_run.
8
9
10
|
# File 'lib/specjour/manager.rb', line 8
def specs_to_run
@specs_to_run
end
|
#worker_pids ⇒ Object
Returns the value of attribute worker_pids.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def worker_pids
@worker_pids
end
|
#worker_size ⇒ Object
Returns the value of attribute worker_size.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def worker_size
@worker_size
end
|
Instance Method Details
#available_for?(project_name) ⇒ Boolean
18
19
20
|
# File 'lib/specjour/manager.rb', line 18
def available_for?(project_name)
registered_projects ? registered_projects.include?(project_name) : true
end
|
#bundle_install ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/specjour/manager.rb', line 22
def bundle_install
Dir.chdir(project_path) do
unless system('bundle check > /dev/null')
system("bundle install --relock > /dev/null")
end
end
end
|
#compile_fastor ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/specjour/manager.rb', line 52
def compile_fastor
puts "Compiling fastor..."
system "cd #{project_path} && rake fastor"
end
|
#dispatch ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/specjour/manager.rb', line 43
def dispatch
suspend_bonjour do
sync
FileUtils.mkdir_p("#{project_path}/tmp/cache")
compile_fastor
dispatch_workers
end
end
|
#dispatch_workers ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/specjour/manager.rb', line 65
def dispatch_workers
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
(1..worker_size).each do |index|
worker_pids << fork do
exec("specjour --batch-size #{batch_size} #{'--log' if Specjour.log?} --do-work #{project_path},#{dispatcher_uri},#{index}")
Kernel.exit!
end
end
at_exit { kill_worker_processes }
Process.waitall
end
|
#drb_start ⇒ Object
85
86
87
88
89
|
# File 'lib/specjour/manager.rb', line 85
def drb_start
DRb.start_service nil, self
puts "Manager started at #{drb_uri}"
at_exit { DRb.stop_service }
end
|
#kill_worker_processes ⇒ Object
35
36
37
|
# File 'lib/specjour/manager.rb', line 35
def kill_worker_processes
Process.kill('TERM', *worker_pids) rescue nil
end
|
#project_path ⇒ Object
39
40
41
|
# File 'lib/specjour/manager.rb', line 39
def project_path
File.join("/tmp", project_name)
end
|
#start ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/specjour/manager.rb', line 77
def start
drb_start
puts "Workers ready: #{worker_size}"
bonjour_announce
Signal.trap('INT') { puts; puts "Shutting down manager..."; exit }
DRb.thread.join
end
|
#sync ⇒ Object
91
92
93
|
# File 'lib/specjour/manager.rb', line 91
def sync
cmd "rsync -aL --delete --port=8989 #{dispatcher_uri.host}::#{project_name} #{project_path}"
end
|