Class: Parallax::Worker
- Inherits:
-
Object
- Object
- Parallax::Worker
- Defined in:
- lib/parallax/worker.rb
Instance Attribute Summary collapse
-
#collector ⇒ Object
The collector object.
-
#index ⇒ Integer
The index of this worker.
Instance Method Summary collapse
-
#close ⇒ nil
Closes the worker and alerts the collector.
-
#initialize(collector, index) ⇒ Worker
constructor
Creates a new worker referred to the specified collector, and with the given index.
-
#log(message) ⇒ nil
Logs the message to the collector.
-
#pack(*args) ⇒ String
Packs the message before sending it to the sending stream.
-
#rescue(error) ⇒ nil
Rescues an error from the worker and sends it to the collector.
-
#send(*args) ⇒ nil
Sends the message to the sending stream.
-
#store(object) ⇒ nil
Stores the object in the collector.
Constructor Details
#initialize(collector, index) ⇒ Worker
Creates a new worker referred to the specified collector, and with the given index.
17 18 19 20 |
# File 'lib/parallax/worker.rb', line 17 def initialize(collector, index) @collector = collector @index = index end |
Instance Attribute Details
#collector ⇒ Object
5 6 7 |
# File 'lib/parallax/worker.rb', line 5 def collector @collector end |
#index ⇒ Integer
7 8 9 |
# File 'lib/parallax/worker.rb', line 7 def index @index end |
Instance Method Details
#close ⇒ nil
Closes the worker and alerts the collector.
76 77 78 |
# File 'lib/parallax/worker.rb', line 76 def close @collector.sending_stream.puts pack(:close_worker) end |
#log(message) ⇒ nil
Logs the message to the collector.
48 49 50 |
# File 'lib/parallax/worker.rb', line 48 def log() @collector.sending_stream.puts pack(:log, ) end |
#pack(*args) ⇒ String
Packs the message before sending it to the sending stream.
28 29 30 |
# File 'lib/parallax/worker.rb', line 28 def pack(*args) [ self.index, *args ].to_yaml.gsub("\n", "\t") end |
#rescue(error) ⇒ nil
Rescues an error from the worker and sends it to the collector.
68 69 70 |
# File 'lib/parallax/worker.rb', line 68 def rescue(error) @collector.sending_stream.puts pack(:rescue, error.class, error.) end |
#send(*args) ⇒ nil
Sends the message to the sending stream.
38 39 40 |
# File 'lib/parallax/worker.rb', line 38 def send(*args) @collector.sending_stream.puts pack(*args) end |
#store(object) ⇒ nil
Stores the object in the collector.
58 59 60 |
# File 'lib/parallax/worker.rb', line 58 def store(object) @collector.sending_stream.puts pack(:store, object) end |