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, 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, recorder = nil) ⇒ Worker
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jcukeforker/worker.rb', line 19 def initialize(status_path, task_path, recorder = nil) @status_path = status_path @task_path = task_path if ENV['DISPLAY'] && recorder config = JSON.parse(recorder) add_observer JCukeForker::RecordingVncListener.new(self, config) end @status_socket = TCPSocket.new 'localhost', status_path @status = nil end |
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
17 18 19 |
# File 'lib/jcukeforker/worker.rb', line 17 def basename @basename end |
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
17 18 19 |
# File 'lib/jcukeforker/worker.rb', line 17 def feature @feature end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
17 18 19 |
# File 'lib/jcukeforker/worker.rb', line 17 def format @format end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
17 18 19 |
# File 'lib/jcukeforker/worker.rb', line 17 def out @out end |
Instance Method Details
#args ⇒ Object
85 86 87 88 89 90 |
# File 'lib/jcukeforker/worker.rb', line 85 def args args = Array(format).flat_map { |f| %W[--format #{f} --out #{output(f)}] } args += @extra_args args << feature args end |
#close ⇒ Object
35 36 37 38 |
# File 'lib/jcukeforker/worker.rb', line 35 def close @worker_server.close @status_socket.close end |
#failed? ⇒ Boolean
68 69 70 |
# File 'lib/jcukeforker/worker.rb', line 68 def failed? @status.nil? || !@status end |
#output(format = nil) ⇒ Object
72 73 74 75 |
# File 'lib/jcukeforker/worker.rb', line 72 def output(format = nil) format = @format if format.nil? File.join out, "#{basename}.#{format}" end |
#register ⇒ Object
30 31 32 33 |
# File 'lib/jcukeforker/worker.rb', line 30 def register @worker_server = UNIXServer.new @task_path update_status :on_worker_register end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jcukeforker/worker.rb', line 40 def run worker_socket = @worker_server.accept loop do = worker_socket.gets if .nil? then sleep 0.3 next end if .strip == '__KILL__' update_status :on_worker_dead break end set_state update_status :on_task_starting, feature status = execute_cucumber update_status :on_task_finished, feature, status end end |
#stderr ⇒ Object
81 82 83 |
# File 'lib/jcukeforker/worker.rb', line 81 def stderr File.join out, "#{basename}.stderr" end |
#stdout ⇒ Object
77 78 79 |
# File 'lib/jcukeforker/worker.rb', line 77 def stdout File.join out, "#{basename}.stdout" end |
#update_status(meth, *args) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/jcukeforker/worker.rb', line 59 def update_status(meth, *args) = [meth, @task_path] += args changed notify_observers * @status_socket.puts(.to_json) end |