Class: QueueBus::TaskManager

Inherits:
Object
  • Object
show all
Defined in:
lib/queue_bus/task_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logging) ⇒ TaskManager

Returns a new instance of TaskManager.



6
7
8
# File 'lib/queue_bus/task_manager.rb', line 6

def initialize(logging)
  @logging = logging
end

Instance Attribute Details

#loggingObject (readonly)

Returns the value of attribute logging.



4
5
6
# File 'lib/queue_bus/task_manager.rb', line 4

def logging
  @logging
end

Instance Method Details

#log(message) ⇒ Object



48
49
50
# File 'lib/queue_bus/task_manager.rb', line 48

def log(message)
  puts(message) if logging
end

#queue_namesObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/queue_bus/task_manager.rb', line 36

def queue_names
  # let's not talk to redis in here. Seems to screw things up
  queues = []
  ::QueueBus.dispatchers.each do |dispatcher|
    dispatcher.subscriptions.all.each do |sub|
      queues << sub.queue_name
    end
  end
  
  queues.uniq
end

#subscribe!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/queue_bus/task_manager.rb', line 10

def subscribe!
  count = 0
  ::QueueBus.dispatchers.each do |dispatcher|
    subscriptions = dispatcher.subscriptions
    if subscriptions.size > 0
      count += subscriptions.size
      log "Subscribing #{dispatcher.app_key} to #{subscriptions.size} subscriptions"
      app = ::QueueBus::Application.new(dispatcher.app_key)
      app.subscribe(subscriptions, logging)
      log "  ...done"
    end
  end
  count
end

#unsubscribe!Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/queue_bus/task_manager.rb', line 25

def unsubscribe!
  count = 0
  ::QueueBus.dispatchers.each do |dispatcher|
    log "Unsubcribing from #{dispatcher.app_key}"
    app = ::QueueBus::Application.new(dispatcher.app_key)
    app.unsubscribe
    count += 1
    log "  ...done"
  end
end