Class: Workling::Clients::MemoryQueueClient
- Inherits:
-
BrokerBase
- Object
- Base
- BrokerBase
- Workling::Clients::MemoryQueueClient
- Defined in:
- lib/workling/clients/memory_queue_client.rb
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
-
#initialize ⇒ MemoryQueueClient
constructor
A new instance of MemoryQueueClient.
-
#request(work_type, arguments) ⇒ Object
immediately invokes the required worker block.
- #retrieve(work_type) ⇒ Object
-
#subscribe(work_type, &block) ⇒ Object
collects the worker blocks in a hash.
Methods inherited from BrokerBase
Methods inherited from Base
#dispatch, installed?, load, #logger
Constructor Details
#initialize ⇒ MemoryQueueClient
Returns a new instance of MemoryQueueClient.
5 6 7 8 |
# File 'lib/workling/clients/memory_queue_client.rb', line 5 def initialize @subscribers ||= {} @queues ||= {} end |
Instance Method Details
#close ⇒ Object
31 |
# File 'lib/workling/clients/memory_queue_client.rb', line 31 def close; true; end |
#connect ⇒ Object
30 |
# File 'lib/workling/clients/memory_queue_client.rb', line 30 def connect; true; end |
#request(work_type, arguments) ⇒ Object
immediately invokes the required worker block
16 17 18 19 20 21 22 23 |
# File 'lib/workling/clients/memory_queue_client.rb', line 16 def request(work_type, arguments) if subscription = @subscribers[work_type] subscription.call(arguments) else @queues[work_type] ||= [] @queues[work_type] << arguments end end |
#retrieve(work_type) ⇒ Object
25 26 27 28 |
# File 'lib/workling/clients/memory_queue_client.rb', line 25 def retrieve(work_type) queue = @queues[work_type] queue.pop if queue end |
#subscribe(work_type, &block) ⇒ Object
collects the worker blocks in a hash
11 12 13 |
# File 'lib/workling/clients/memory_queue_client.rb', line 11 def subscribe(work_type, &block) @subscribers[work_type] = block end |