Class: JCukeForker::Worker
- Inherits:
-
Object
- Object
- JCukeForker::Worker
- Includes:
- Observable
- Defined in:
- lib/jcukeforker/worker.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Instance Method Summary collapse
- #args ⇒ Object
- #close ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(status_path, task_path, worker_num, recorder = nil) ⇒ Worker
constructor
A new instance of Worker.
- #output(format = nil) ⇒ Object
- #register ⇒ Object
- #run ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #update_status(meth, *args) ⇒ Object
Constructor Details
#initialize(status_path, task_path, worker_num, recorder = nil) ⇒ Worker
Returns a new instance of Worker.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jcukeforker/worker.rb', line 18 def initialize(status_path, task_path, worker_num, recorder = nil) @status_path = status_path @task_path = task_path @worker_num = worker_num if ENV['DISPLAY'] && recorder config = JSON.parse(recorder) add_observer JCukeForker::RecordingVncListener.new(self, config) end @status_file = File.open(status_path, 'a') @status_file.sync = true @status = nil end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
16 17 18 |
# File 'lib/jcukeforker/worker.rb', line 16 def basename @basename end |
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
16 17 18 |
# File 'lib/jcukeforker/worker.rb', line 16 def feature @feature end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
16 17 18 |
# File 'lib/jcukeforker/worker.rb', line 16 def format @format end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
16 17 18 |
# File 'lib/jcukeforker/worker.rb', line 16 def out @out end |
Instance Method Details
#args ⇒ Object
88 89 90 91 92 93 |
# File 'lib/jcukeforker/worker.rb', line 88 def args args = Array(format).flat_map { |f| %W[--format #{f} --out #{output(f)}] } args += @extra_args args << feature args end |
#close ⇒ Object
36 37 38 39 |
# File 'lib/jcukeforker/worker.rb', line 36 def close @event_file.close @status_file.close end |
#failed? ⇒ Boolean
71 72 73 |
# File 'lib/jcukeforker/worker.rb', line 71 def failed? @status.nil? || !@status end |
#output(format = nil) ⇒ Object
75 76 77 78 |
# File 'lib/jcukeforker/worker.rb', line 75 def output(format = nil) format = @format if format.nil? File.join out, "#{basename}.#{format}" end |
#register ⇒ Object
31 32 33 34 |
# File 'lib/jcukeforker/worker.rb', line 31 def register @event_file = File.open(@task_path, 'r') update_status :on_worker_register end |
#run ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jcukeforker/worker.rb', line 41 def run loop do = @event_file.gets(sep=$-0) if .nil? then sleep 0.1 next end json_obj = JSON.parse next unless json_obj['worker'] == @worker_num if json_obj['action'] == '__KILL__' update_status :on_worker_dead break end set_state json_obj update_status :on_task_starting, feature status = execute_cucumber update_status :on_task_finished, feature, status end end |
#stderr ⇒ Object
84 85 86 |
# File 'lib/jcukeforker/worker.rb', line 84 def stderr File.join out, "#{basename}.stderr" end |
#stdout ⇒ Object
80 81 82 |
# File 'lib/jcukeforker/worker.rb', line 80 def stdout File.join out, "#{basename}.stdout" end |
#update_status(meth, *args) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/jcukeforker/worker.rb', line 61 def update_status(meth, *args) = [meth, @worker_num] += args changed notify_observers * @status_file.write("#{.to_json}#{$-0}") end |