Sha256: 13ff9802971583d2c8909d6a1094b177885b8f1602aa288125a9a1c4fa1d5af7

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

Contents

module ResqueBus
  class TaskManager

    attr_reader :logging
    
    def initialize(logging)
      @logging = logging
    end
    
    def subscribe!
      count = 0
      ResqueBus.dispatchers.each do |dispatcher|
        subscriptions = dispatcher.subscriptions
        if subscriptions.size > 0
          count += subscriptions.size
          log "Subscribing #{dispatcher.app_key} to #{subscriptions.size} subscriptions"
          app = ResqueBus::Application.new(dispatcher.app_key)
          app.subscribe(subscriptions, logging)
          log "  ...done"
        end
      end
      count
    end
    
    def unsubscribe!
      count = 0
      ResqueBus.dispatchers.each do |dispatcher|
        log "Unsubcribing from #{dispatcher.app_key}"
        app = ResqueBus::Application.new(dispatcher.app_key)
        app.unsubscribe
        count += 1
        log "  ...done"
      end
    end
    
    def queue_names
      # let's not talk to redis in here. Seems to screw things up
      queues = []
      ResqueBus.dispatchers.each do |dispatcher|
        dispatcher.subscriptions.all.each do |sub|
          queues << sub.queue_name
        end
      end
      
      queues.uniq
    end
    
    def log(message)
      puts(message) if logging
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
resque-bus-0.3.7 lib/resque_bus/task_manager.rb
resque-bus-0.3.6 lib/resque_bus/task_manager.rb
resque-bus-0.3.5 lib/resque_bus/task_manager.rb
resque-bus-0.3.4 lib/resque_bus/task_manager.rb
resque-bus-0.3.3 lib/resque_bus/task_manager.rb
resque-bus-0.3.2 lib/resque_bus/task_manager.rb
resque-bus-0.3.1 lib/resque_bus/task_manager.rb
resque-bus-0.3.0 lib/resque_bus/task_manager.rb
resque-bus-0.2.10 lib/resque_bus/task_manager.rb
resque-bus-0.2.9 lib/resque_bus/task_manager.rb
resque-bus-0.2.8 lib/resque_bus/task_manager.rb
resque-bus-0.2.7 lib/resque_bus/task_manager.rb
resque-bus-0.2.6 lib/resque_bus/task_manager.rb
resque-bus-0.2.5 lib/resque_bus/task_manager.rb