Class: Rcom::Task
- Inherits:
-
Object
- Object
- Rcom::Task
- Defined in:
- lib/rcom/task.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(params) ⇒ Task
constructor
A new instance of Task.
- #publish(message) ⇒ Object
- #subscribe ⇒ Object
Constructor Details
#initialize(params) ⇒ Task
Returns a new instance of Task.
5 6 7 8 |
# File 'lib/rcom/task.rb', line 5 def initialize(params) @node = params[:node] @channel = params[:channel] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
3 4 5 |
# File 'lib/rcom/task.rb', line 3 def channel @channel end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'lib/rcom/task.rb', line 3 def node @node end |
Instance Method Details
#publish(message) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/rcom/task.rb', line 10 def publish() begin node.lpush(channel, .to_msgpack) return true rescue return nil end end |
#subscribe ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rcom/task.rb', line 19 def subscribe begin loop do ch, request = node.brpop(channel) = MessagePack.unpack( request, symbolize_keys: true ) yield end rescue Interrupt => _ end end |