Sha256: 9766d328eb8d8439a04cef1fbcb54f2914793f633a080a11369cc2d9dc396a8b

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

module ResqueBus
  # fans out an event to multiple queues
  class Driver

    class << self
      def subscription_matches(attributes)
        out = []
        Application.all.each do |app|
          subs = app.subscription_matches(attributes)
          out.concat(subs)
        end
        out
      end

      def perform(attributes={})
        raise "No attribiutes passed" if attributes.empty?

        ResqueBus.log_worker("Driver running: #{attributes.inspect}")

        subscription_matches(attributes).each do |sub|
          ResqueBus.log_worker("  ...sending to #{sub.queue_name} queue with class #{sub.class_name} for app #{sub.app_key} because of subscription: #{sub.key}")
          
          bus_attr = {"bus_driven_at" => Time.now.to_i, "bus_rider_queue" => sub.queue_name, "bus_rider_app_key" => sub.app_key, "bus_rider_sub_key" => sub.key, "bus_rider_class_name" => sub.class_name}
          ResqueBus.enqueue_to(sub.queue_name, sub.class_name, bus_attr.merge(attributes || {}))
        end
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
resque-bus-0.2.10 lib/resque_bus/driver.rb
resque-bus-0.2.9 lib/resque_bus/driver.rb
resque-bus-0.2.8 lib/resque_bus/driver.rb
resque-bus-0.2.7 lib/resque_bus/driver.rb
resque-bus-0.2.6 lib/resque_bus/driver.rb
resque-bus-0.2.5 lib/resque_bus/driver.rb