Class: QueueBus::TaskManager

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

Overview

A helper class for executing Rake tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logging) ⇒ TaskManager

Returns a new instance of TaskManager.



8
9
10
# File 'lib/queue_bus/task_manager.rb', line 8

def initialize(logging)
  @logging = logging
end

Instance Attribute Details

#loggingObject (readonly)

Returns the value of attribute logging.



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

def logging
  @logging
end

Instance Method Details

#log(message) ⇒ Object



50
51
52
# File 'lib/queue_bus/task_manager.rb', line 50

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

#queue_namesObject



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

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



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

def subscribe!
  count = 0
  ::QueueBus.dispatchers.each do |dispatcher|
    subscriptions = dispatcher.subscriptions
    next if subscriptions.empty?

    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
  count
end

#unsubscribe!Object



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

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