Class: Specjour::Worker

Inherits:
Object
  • Object
show all
Includes:
Protocol
Defined in:
lib/specjour/worker.rb

Constant Summary

Constants included from Protocol

Protocol::TERMINATOR, Protocol::TERMINATOR_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Protocol

#dump_object, #load_object

Constructor Details

#initialize(project_path, printer_uri, number, batch_size) ⇒ Worker

Returns a new instance of Worker.



7
8
9
10
11
12
13
14
15
16
# File 'lib/specjour/worker.rb', line 7

def initialize(project_path, printer_uri, number, batch_size)
  @project_path = project_path
  @specs_to_run = specs_to_run
  @number = number.to_i
  @batch_size = batch_size.to_i
  self.printer_uri = printer_uri
  GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
  DistributedFormatter.batch_size = batch_size
  set_env_variables
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



5
6
7
# File 'lib/specjour/worker.rb', line 5

def batch_size
  @batch_size
end

#numberObject (readonly)

Returns the value of attribute number.



5
6
7
# File 'lib/specjour/worker.rb', line 5

def number
  @number
end

#printer_uriObject

Returns the value of attribute printer_uri.



4
5
6
# File 'lib/specjour/worker.rb', line 4

def printer_uri
  @printer_uri
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



5
6
7
# File 'lib/specjour/worker.rb', line 5

def project_path
  @project_path
end

#specs_to_runObject (readonly)

Returns the value of attribute specs_to_run.



5
6
7
# File 'lib/specjour/worker.rb', line 5

def specs_to_run
  @specs_to_run
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/specjour/worker.rb', line 22

def run
  printer.send_message(:ready)
  run_time = 0
  Dir.chdir(project_path)
  while !printer.closed? && data = printer.gets(TERMINATOR)
    spec = load_object(data)
    if spec
      run_time += Benchmark.realtime do
        run_spec spec
      end
      printer.send_message(:ready)
    else
      printer.send_message(:done)
      printer.send_message(:worker_summary=, {:duration => sprintf("%6f", run_time)})
      printer.close
    end
  end
end