Class: Specjour::Manager
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fork
fork, fork_quietly
#current_uri, #hostname, #ip_from_hostname, #local_ip, #new_uri
Constructor Details
#initialize(options = {}) ⇒ Manager
Returns a new instance of Manager.
19
20
21
22
23
24
25
26
|
# File 'lib/specjour/manager.rb', line 19
def initialize(options = {})
@options = options
@worker_size = options[:worker_size]
@worker_task = options[:worker_task]
@registered_projects = options[:registered_projects]
@rsync_port = options[:rsync_port]
Specjour.load_custom_hooks
end
|
Instance Attribute Details
#dispatcher_uri ⇒ Object
Returns the value of attribute dispatcher_uri.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def dispatcher_uri
@dispatcher_uri
end
|
#loader_pid ⇒ Object
Returns the value of attribute loader_pid.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def loader_pid
@loader_pid
end
|
#options ⇒ Object
Returns the value of attribute options.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def options
@options
end
|
#pid ⇒ Object
Returns the value of attribute pid.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def pid
@pid
end
|
#project_name ⇒ Object
Returns the value of attribute project_name.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def project_name
@project_name
end
|
#registered_projects ⇒ Object
Returns the value of attribute registered_projects.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def registered_projects
@registered_projects
end
|
#rsync_port ⇒ Object
Returns the value of attribute rsync_port.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def rsync_port
@rsync_port
end
|
#test_paths ⇒ Object
Returns the value of attribute test_paths.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def test_paths
@test_paths
end
|
#worker_size ⇒ Object
Returns the value of attribute worker_size.
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def worker_size
@worker_size
end
|
#worker_task ⇒ Object
Returns the value of attribute worker_task.
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def worker_task
@worker_task
end
|
Class Method Details
.start_quietly(options) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/specjour/manager.rb', line 12
def self.start_quietly(options)
manager = new options.merge(:quiet => true)
manager.drb_uri
manager.pid = Fork.fork_quietly { manager.start }
manager
end
|
Instance Method Details
#available_for?(project_name) ⇒ Boolean
28
29
30
|
# File 'lib/specjour/manager.rb', line 28
def available_for?(project_name)
registered_projects ? registered_projects.include?(project_name) : false
end
|
#dispatch ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/specjour/manager.rb', line 37
def dispatch
suspend_bonjour do
sync
with_clean_env do
execute_before_fork
dispatch_loader
end
end
end
|
#dispatch_loader ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/specjour/manager.rb', line 60
def dispatch_loader
@loader_pid = fork do
exec_cmd = "load --printer-uri #{dispatcher_uri} --workers #{worker_size} --task #{worker_task} --project-path #{project_path}"
exec_cmd << " --test-paths #{test_paths.join(" ")}" if test_paths.any?
exec_cmd << " --log" if Specjour.log?
exec_cmd << " --quiet" if quiet?
specjour_path = $LOAD_PATH.detect {|l| l =~ %r(specjour[^/]*/lib$)}
bin_path = File.expand_path(File.join(specjour_path, "../bin"))
Kernel.exec({"RUBYLIB" => $LOAD_PATH.join(":")}, "#{bin_path}/specjour #{exec_cmd}")
end
Process.waitall
ensure
kill_loader_process if loader_pid
end
|
#drb_start ⇒ Object
47
48
49
50
51
|
# File 'lib/specjour/manager.rb', line 47
def drb_start
$PROGRAM_NAME = "specjour listen" if quiet?
DRb.start_service drb_uri.to_s, self
at_exit { DRb.stop_service }
end
|
#drb_uri ⇒ Object
53
54
55
56
57
58
|
# File 'lib/specjour/manager.rb', line 53
def drb_uri
@drb_uri ||= begin
current_uri.scheme = "druby"
current_uri
end
end
|
#in_project(&block) ⇒ Object
75
76
77
|
# File 'lib/specjour/manager.rb', line 75
def in_project(&block)
Dir.chdir(project_path, &block)
end
|
#interrupted=(bool) ⇒ Object
79
80
81
82
|
# File 'lib/specjour/manager.rb', line 79
def interrupted=(bool)
Specjour.interrupted = bool
kill_loader_process if loader_pid
end
|
#kill_loader_process ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/specjour/manager.rb', line 84
def kill_loader_process
if Specjour.interrupted?
Process.kill('INT', loader_pid) rescue Errno::ESRCH
else
Process.kill('TERM', loader_pid) rescue Errno::ESRCH
end
@loader_pid = nil
end
|
#project_path ⇒ Object
97
98
99
|
# File 'lib/specjour/manager.rb', line 97
def project_path
File.expand_path(project_name, File.realpath('/tmp'))
end
|
#quiet? ⇒ Boolean
108
109
110
|
# File 'lib/specjour/manager.rb', line 108
def quiet?
options.has_key? :quiet
end
|
#start ⇒ Object
101
102
103
104
105
106
|
# File 'lib/specjour/manager.rb', line 101
def start
drb_start
bonjour_announce
at_exit { stop_bonjour }
DRb.thread.join
end
|
#sync ⇒ Object
112
113
114
|
# File 'lib/specjour/manager.rb', line 112
def sync
cmd "rsync #{Specjour::Configuration.rsync_options} --port=#{rsync_port} #{dispatcher_uri.host}::#{project_name} #{project_path}"
end
|