Class: Parallax::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/parallax/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#collectorObject



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

def collector
  @collector
end

#indexInteger



7
8
9
# File 'lib/parallax/worker.rb', line 7

def index
  @index
end

Instance Method Details

#closenil

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(message)
  @collector.sending_stream.puts pack(:log, message)
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.message)
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