Sha256: 41c138b990442741ee4332a9e0fa2874e6f4c63215c1fb9792d69e42d12ed1a6

Contents?: true

Size: 1.24 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
resque-bus-0.2.4 lib/resque_bus/task_manager.rb
resque-bus-0.2.3 lib/resque_bus/task_manager.rb