Class: ResqueBus::Application
- Inherits:
-
Object
- Object
- ResqueBus::Application
- Defined in:
- lib/resque_bus/application.rb
Instance Attribute Summary collapse
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
-
#redis_key ⇒ Object
readonly
Returns the value of attribute redis_key.
Class Method Summary collapse
Instance Method Summary collapse
- #event_display_tuples ⇒ Object
-
#initialize(app_key) ⇒ Application
constructor
A new instance of Application.
- #no_connect_queue_names_for(subscriptions) ⇒ Object
- #subscribe(subscription_list, log = false) ⇒ Object
- #subscription_matches(attributes) ⇒ Object
- #unsubscribe ⇒ Object
Constructor Details
#initialize(app_key) ⇒ Application
Returns a new instance of Application.
15 16 17 18 19 20 |
# File 'lib/resque_bus/application.rb', line 15 def initialize(app_key) @app_key = self.class.normalize(app_key) @redis_key = "#{self.class.app_single_key}:#{@app_key}" # raise error if only other chars raise "Invalid application name" if @app_key.gsub("_", "").size == 0 end |
Instance Attribute Details
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
12 13 14 |
# File 'lib/resque_bus/application.rb', line 12 def app_key @app_key end |
#redis_key ⇒ Object (readonly)
Returns the value of attribute redis_key.
12 13 14 |
# File 'lib/resque_bus/application.rb', line 12 def redis_key @redis_key end |
Class Method Details
.all ⇒ Object
6 7 8 9 |
# File 'lib/resque_bus/application.rb', line 6 def all # note the names arent the same as we started with ResqueBus.redis.smembers(app_list_key).collect{ |val| new(val) } end |
Instance Method Details
#event_display_tuples ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/resque_bus/application.rb', line 72 def event_display_tuples out = [] subscriptions.all.each do |sub| out << [sub.class_name, sub.queue_name, sub.matcher.filters] end out end |
#no_connect_queue_names_for(subscriptions) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/resque_bus/application.rb', line 54 def no_connect_queue_names_for(subscriptions) out = [] subscriptions.all.each do |sub| queue = "#{app_key}_#{sub.queue_name}" out << queue end out << "#{app_key}_default" out.uniq end |
#subscribe(subscription_list, log = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/resque_bus/application.rb', line 22 def subscribe(subscription_list, log = false) @subscriptions = nil if subscription_list == nil || subscription_list.size == 0 unsubscribe return true end temp_key = "temp_#{redis_key}:#{rand(999999999)}" redis_hash = subscription_list.to_redis redis_hash.each do |key, hash| ResqueBus.redis.hset(temp_key, key, Resque.encode(hash)) end # make it the real one ResqueBus.redis.rename(temp_key, redis_key) ResqueBus.redis.sadd(self.class.app_list_key, app_key) if log puts ResqueBus.redis.hgetall(redis_key).inspect end true end |
#subscription_matches(attributes) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/resque_bus/application.rb', line 64 def subscription_matches(attributes) out = subscriptions.matches(attributes) out.each do |sub| sub.app_key = self.app_key end out end |
#unsubscribe ⇒ Object
48 49 50 51 52 |
# File 'lib/resque_bus/application.rb', line 48 def unsubscribe # TODO: clean up known queues? ResqueBus.redis.srem(self.class.app_list_key, app_key) ResqueBus.redis.del(redis_key) end |