Class: Nitra::Workers::Worker
- Inherits:
-
Object
- Object
- Nitra::Workers::Worker
- Defined in:
- lib/nitra/worker.rb
Constant Summary collapse
- @@worker_classes =
{}
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#runner_id ⇒ Object
readonly
Returns the value of attribute runner_id.
-
#worker_number ⇒ Object
readonly
Returns the value of attribute worker_number.
Class Method Summary collapse
-
.framework_name ⇒ Object
Return the framework name of this worker.
- .inherited(klass) ⇒ Object
- .worker_classes ⇒ Object
Instance Method Summary collapse
- #fork_and_run ⇒ Object
-
#initialize(runner_id, worker_number, configuration) ⇒ Worker
constructor
A new instance of Worker.
Constructor Details
#initialize(runner_id, worker_number, configuration) ⇒ Worker
Returns a new instance of Worker.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nitra/worker.rb', line 30 def initialize(runner_id, worker_number, configuration) @runner_id = runner_id @worker_number = worker_number @configuration = configuration @forked_worker_pid = nil ENV["TEST_ENV_NUMBER"] = worker_number.to_s # Frameworks don't like it when you change the IO between invocations. # So we make one object and flush it after every invocation. @io = StringIO.new end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
28 29 30 |
# File 'lib/nitra/worker.rb', line 28 def channel @channel end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
28 29 30 |
# File 'lib/nitra/worker.rb', line 28 def configuration @configuration end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
28 29 30 |
# File 'lib/nitra/worker.rb', line 28 def io @io end |
#runner_id ⇒ Object (readonly)
Returns the value of attribute runner_id.
28 29 30 |
# File 'lib/nitra/worker.rb', line 28 def runner_id @runner_id end |
#worker_number ⇒ Object (readonly)
Returns the value of attribute worker_number.
28 29 30 |
# File 'lib/nitra/worker.rb', line 28 def worker_number @worker_number end |
Class Method Details
.framework_name ⇒ Object
Return the framework name of this worker
22 23 24 |
# File 'lib/nitra/worker.rb', line 22 def framework_name self.name.split("::").last.downcase end |
.inherited(klass) ⇒ Object
11 12 13 |
# File 'lib/nitra/worker.rb', line 11 def inherited(klass) @@worker_classes[klass.framework_name] = klass end |
.worker_classes ⇒ Object
15 16 17 |
# File 'lib/nitra/worker.rb', line 15 def worker_classes @@worker_classes end |
Instance Method Details
#fork_and_run ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nitra/worker.rb', line 44 def fork_and_run client, server = Nitra::Channel.pipe pid = fork do # This is important. We don't want anything bubbling up to the master that we didn't send there. # We reopen later to get the output from the framework run. $stdout.reopen('/dev/null', 'a') $stderr.reopen('/dev/null', 'a') trap("USR1") { interrupt_forked_worker_and_exit } server.close @channel = client begin run rescue => e channel.write("command" => "error", "process" => "init framework", "text" => e., "worker_number" => worker_number) end end client.close [pid, server] end |