Class: Specjour::Manager
- Inherits:
-
Object
show all
- Includes:
- DRbUndumped, Fork, SocketHelper
- Defined in:
- lib/specjour/manager.rb
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, #new_uri
Constructor Details
- (Manager) initialize(options = {})
A new instance of Manager
19
20
21
22
23
24
25
|
# 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]
end
|
Instance Attribute Details
- (Object) dispatcher_uri
Returns the value of attribute dispatcher_uri
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def dispatcher_uri
@dispatcher_uri
end
|
- (Object) loader_pid
Returns the value of attribute loader_pid
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def loader_pid
@loader_pid
end
|
- (Object) options
Returns the value of attribute options
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def options
@options
end
|
- (Object) pid
Returns the value of attribute pid
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def pid
@pid || Process.pid
end
|
- (Object) project_name
Returns the value of attribute project_name
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def project_name
@project_name
end
|
- (Object) registered_projects
Returns the value of attribute registered_projects
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def registered_projects
@registered_projects
end
|
- (Object) rsync_port
Returns the value of attribute rsync_port
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def rsync_port
@rsync_port
end
|
- (Object) test_paths
Returns the value of attribute test_paths
9
10
11
|
# File 'lib/specjour/manager.rb', line 9
def test_paths
@test_paths
end
|
- (Object) worker_size
Returns the value of attribute worker_size
10
11
12
|
# File 'lib/specjour/manager.rb', line 10
def worker_size
@worker_size
end
|
- (Object) worker_task
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
+ (Object) start_quietly(options)
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
- (Boolean) available_for?(project_name)
27
28
29
|
# File 'lib/specjour/manager.rb', line 27
def available_for?(project_name)
registered_projects ? registered_projects.include?(project_name) : false
end
|
- (Object) dispatch
36
37
38
39
40
41
42
43
44
|
# File 'lib/specjour/manager.rb', line 36
def dispatch
suspend_bonjour do
sync
with_clean_env do
execute_before_fork
dispatch_loader
end
end
end
|
- (Object) dispatch_loader
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/specjour/manager.rb', line 59
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?
load_path = $LOAD_PATH.detect {|l| l =~ %r(specjour[^/]*/lib$)}
bin_path = File.expand_path(File.join(load_path, "../bin"))
Kernel.exec({"RUBYLIB" => load_path}, "#{bin_path}/specjour #{exec_cmd}")
end
Process.waitall
ensure
kill_loader_process if loader_pid
end
|
- (Object) drb_start
46
47
48
49
50
|
# File 'lib/specjour/manager.rb', line 46
def drb_start
$PROGRAM_NAME = "specjour listen" if quiet?
DRb.start_service drb_uri.to_s, self
at_exit { DRb.stop_service }
end
|
- (Object) drb_uri
52
53
54
55
56
57
|
# File 'lib/specjour/manager.rb', line 52
def drb_uri
@drb_uri ||= begin
current_uri.scheme = "druby"
current_uri
end
end
|
- (Object) in_project(&block)
74
75
76
|
# File 'lib/specjour/manager.rb', line 74
def in_project(&block)
Dir.chdir(project_path, &block)
end
|
- (Object) interrupted=(bool)
78
79
80
81
|
# File 'lib/specjour/manager.rb', line 78
def interrupted=(bool)
Specjour.interrupted = bool
kill_loader_process if loader_pid
end
|
- (Object) kill_loader_process
83
84
85
86
87
88
89
90
|
# File 'lib/specjour/manager.rb', line 83
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
|
- (Object) project_path
96
97
98
|
# File 'lib/specjour/manager.rb', line 96
def project_path
File.join("/tmp", project_name)
end
|
- (Boolean) quiet?
107
108
109
|
# File 'lib/specjour/manager.rb', line 107
def quiet?
options.has_key? :quiet
end
|
- (Object) start
100
101
102
103
104
105
|
# File 'lib/specjour/manager.rb', line 100
def start
drb_start
bonjour_announce
at_exit { stop_bonjour }
DRb.thread.join
end
|
- (Object) sync
111
112
113
114
|
# File 'lib/specjour/manager.rb', line 111
def sync
cmd "rsync -aL --delete --ignore-errors --port=#{rsync_port} #{dispatcher_uri.host}::#{project_name} #{project_path}"
puts "rsync complete"
end
|