specjour 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.1.11
@@ -0,0 +1,52 @@
1
+ module Specjour
2
+ class Connection
3
+ MAX_RECONNECTS = 5
4
+
5
+ include Protocol
6
+ extend Forwardable
7
+
8
+ attr_reader :uri, :connection
9
+ attr_accessor :reconnection_attempts
10
+
11
+ def_delegators :connection, :flush, :closed?, :close, :gets, :each
12
+
13
+ def initialize(uri)
14
+ @uri = uri
15
+ @reconnection_attempts = 0
16
+ connect
17
+ end
18
+
19
+ def connect
20
+ @connection = TCPSocket.open(uri.host, uri.port)
21
+ rescue SystemCallError => error
22
+ Kernel.puts "Could not connect to #{uri.to_s}\n#{error.inspect}"
23
+ end
24
+
25
+ def print(arg)
26
+ connection.print dump_object(arg)
27
+ rescue SystemCallError => error
28
+ Kernel.p error
29
+ reconnect
30
+ retry
31
+ end
32
+
33
+ def puts(arg)
34
+ print(arg << "\n")
35
+ end
36
+
37
+ def reconnect
38
+ connection.close
39
+ if reconnection_attempts < MAX_RECONNECTS
40
+ connect
41
+ self.reconnection_attempts += 1
42
+ else
43
+ raise Error, "Lost connection #{MAX_RECONNECTS} times"
44
+ end
45
+ end
46
+
47
+ def send_message(method_name, *args)
48
+ print([method_name, *args])
49
+ flush
50
+ end
51
+ end
52
+ end
@@ -16,8 +16,6 @@ module Specjour
16
16
  def start
17
17
  rsync_daemon.start
18
18
  gather_managers
19
- sync_managers
20
- bundle_install_managers
21
19
  dispatch_work
22
20
  printer.join
23
21
  end
@@ -30,10 +28,6 @@ module Specjour
30
28
  end
31
29
  end
32
30
 
33
- def bundle_install_managers
34
- command_managers {|manager| manager.bundle_install }
35
- end
36
-
37
31
  def command_managers(async = false, &block)
38
32
  managers.each do |manager|
39
33
  manager_threads << Thread.new(manager, &block)
@@ -45,11 +39,6 @@ module Specjour
45
39
  command_managers(true) { |m| m.dispatch }
46
40
  end
47
41
 
48
- def drb_start
49
- DRb.start_service nil, self
50
- at_exit { puts 'shutting down DRb client'; DRb.stop_service }
51
- end
52
-
53
42
  def fetch_manager(uri)
54
43
  manager = DRbObject.new_with_uri(uri.to_s)
55
44
  if !managers.include?(manager) && manager.available_for?(hostname)
@@ -63,11 +52,16 @@ module Specjour
63
52
  puts "Waiting for managers"
64
53
  Signal.trap('INT') { exit }
65
54
  browser = DNSSD::Service.new
66
- browser.browse '_druby._tcp' do |reply|
67
- if reply.flags.add?
68
- resolve_reply(reply)
55
+ begin
56
+ Timeout.timeout(5) do
57
+ browser.browse '_druby._tcp' do |reply|
58
+ if reply.flags.add?
59
+ resolve_reply(reply)
60
+ end
61
+ browser.stop unless reply.flags.more_coming?
62
+ end
69
63
  end
70
- browser.stop unless reply.flags.more_coming?
64
+ rescue Timeout::Error
71
65
  end
72
66
  puts "Managers found: #{managers.size}"
73
67
  abort unless managers.size > 0
@@ -112,10 +106,6 @@ module Specjour
112
106
  at_exit { manager.kill_worker_processes }
113
107
  end
114
108
 
115
- def sync_managers
116
- command_managers { |manager| manager.sync }
117
- end
118
-
119
109
  def wait_on_managers
120
110
  manager_threads.each {|t| t.join; t.exit}
121
111
  reset_manager_threads
@@ -34,7 +34,14 @@ module Specjour
34
34
  end
35
35
 
36
36
  def dispatch
37
- bonjour_service.stop
37
+ suspend_bonjour do
38
+ sync
39
+ bundle_install
40
+ dispatch_workers
41
+ end
42
+ end
43
+
44
+ def dispatch_workers
38
45
  (1..worker_size).each do |index|
39
46
  worker_pids << fork do
40
47
  exec("specjour --batch-size #{batch_size} --do-work #{project_path},#{dispatcher_uri},#{index}")
@@ -43,7 +50,6 @@ module Specjour
43
50
  end
44
51
  at_exit { kill_worker_processes }
45
52
  Process.waitall
46
- bonjour_announce
47
53
  end
48
54
 
49
55
  def start
@@ -65,6 +71,10 @@ module Specjour
65
71
 
66
72
  protected
67
73
 
74
+ def bonjour_announce
75
+ @bonjour_service = DNSSD.register! "specjour_manager_#{object_id}", "_#{drb_uri.scheme}._tcp", nil, drb_uri.port
76
+ end
77
+
68
78
  def cmd(command)
69
79
  puts command
70
80
  system command
@@ -74,8 +84,10 @@ module Specjour
74
84
  @drb_uri ||= URI.parse(DRb.uri)
75
85
  end
76
86
 
77
- def bonjour_announce
78
- @bonjour_service = DNSSD.register! "specjour_manager_#{object_id}", "_#{drb_uri.scheme}._tcp", nil, drb_uri.port
87
+ def suspend_bonjour(&block)
88
+ bonjour_service.stop
89
+ block.call
90
+ bonjour_announce
79
91
  end
80
92
  end
81
93
  end
@@ -10,6 +10,7 @@ module Specjour
10
10
  @number = number.to_i
11
11
  @batch_size = batch_size.to_i
12
12
  self.printer_uri = printer_uri
13
+ printer
13
14
  GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
14
15
  DistributedFormatter.batch_size = batch_size
15
16
  Dir.chdir(project_path)
@@ -22,13 +23,17 @@ module Specjour
22
23
 
23
24
  def run
24
25
  printer.send_message(:ready)
26
+ run_time = 0
25
27
  while !printer.closed? && data = printer.gets(TERMINATOR)
26
28
  spec = load_object(data)
27
29
  if spec
28
- run_spec spec
30
+ run_time += Benchmark.realtime do
31
+ run_spec spec
32
+ end
29
33
  printer.send_message(:ready)
30
34
  else
31
35
  printer.send_message(:done)
36
+ printer.send_message(:worker_summary=, {:duration => sprintf("%6f", run_time)})
32
37
  printer.close
33
38
  end
34
39
  end
@@ -41,7 +46,7 @@ module Specjour
41
46
  end
42
47
 
43
48
  def printer_connection
44
- TCPSocket.open(printer_uri.host, printer_uri.port).extend Protocol
49
+ Connection.new printer_uri
45
50
  end
46
51
 
47
52
  def run_spec(spec)
data/lib/specjour.rb CHANGED
@@ -7,8 +7,11 @@ autoload :URI, 'uri'
7
7
  autoload :DRb, 'drb'
8
8
  autoload :Forwardable, 'forwardable'
9
9
  autoload :GServer, 'gserver'
10
+ autoload :Timeout, 'timeout'
11
+ autoload :Benchmark, 'benchmark'
10
12
 
11
13
  module Specjour
14
+ autoload :Connection, 'specjour/connection'
12
15
  autoload :Dispatcher, 'specjour/dispatcher'
13
16
  autoload :DistributedFormatter, 'specjour/distributed_formatter'
14
17
  autoload :FinalReport, 'specjour/final_report'
@@ -18,5 +21,6 @@ module Specjour
18
21
  autoload :RsyncDaemon, 'specjour/rsync_daemon'
19
22
  autoload :Worker, 'specjour/worker'
20
23
 
21
- VERSION = "0.1.10".freeze
24
+ VERSION = "0.1.11".freeze
25
+ class Error < StandardError; end
22
26
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 10
9
- version: 0.1.10
8
+ - 11
9
+ version: 0.1.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sandro Turriate
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-05 00:00:00 -04:00
17
+ date: 2010-04-06 00:00:00 -04:00
18
18
  default_executable: specjour
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -88,6 +88,7 @@ files:
88
88
  - VERSION
89
89
  - bin/specjour
90
90
  - lib/specjour.rb
91
+ - lib/specjour/connection.rb
91
92
  - lib/specjour/core_ext/array.rb
92
93
  - lib/specjour/db_scrub.rb
93
94
  - lib/specjour/dispatcher.rb