Class: Workling::Clients::MemoryQueueClient

Inherits:
BrokerBase show all
Defined in:
lib/workling/clients/memory_queue_client.rb

Instance Method Summary collapse

Methods inherited from BrokerBase

#dispatch

Methods inherited from Base

#dispatch, installed?, load, #logger

Constructor Details

#initializeMemoryQueueClient

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

#closeObject



31
# File 'lib/workling/clients/memory_queue_client.rb', line 31

def close; true; end

#connectObject



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