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



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



64
65
66
# File 'lib/queue_bus/task_manager.rb', line 64

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

#queue_namesObject



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/queue_bus/task_manager.rb', line 52

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



41
42
43
44
45
46
47
48
49
50
# File 'lib/queue_bus/task_manager.rb', line 41

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

#unsubscribe_app!(app_key) ⇒ Object



34
35
36
37
38
39
# File 'lib/queue_bus/task_manager.rb', line 34

def unsubscribe_app!(app_key)
  log "Removing all subscriptions for #{app_key}"
  app = ::QueueBus::Application.new(app_key)
  app.unsubscribe
  log "  ...done"
end

#unsubscribe_queue!(app_key, queue) ⇒ Object



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

def unsubscribe_queue!(app_key, queue)
  log "Unsubcribing #{queue} from #{app_key}"
  app = ::QueueBus::Application.new(app_key)
  app.unsubscribe_queue(queue)
  log "  ...done"
end