Class: Fairway::Connection
- Inherits:
-
Object
- Object
- Fairway::Connection
- Defined in:
- lib/fairway/connection.rb
Constant Summary collapse
- DEFAULT_CHANNEL =
"default"
Instance Method Summary collapse
- #deliver(message, channel = DEFAULT_CHANNEL) ⇒ Object
-
#initialize(config = Fairway.config) ⇒ Connection
constructor
A new instance of Connection.
- #queues ⇒ Object
- #redis ⇒ Object
- #register_queues ⇒ Object
- #scripts ⇒ Object
- #subscribe(channel_pattern, &block) ⇒ Object
Constructor Details
#initialize(config = Fairway.config) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 |
# File 'lib/fairway/connection.rb', line 7 def initialize(config = Fairway.config) @config = config register_queues end |
Instance Method Details
#deliver(message, channel = DEFAULT_CHANNEL) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/fairway/connection.rb', line 20 def deliver(, channel = DEFAULT_CHANNEL) scripts.fairway_deliver( channel, @config.facet.call(), .to_json ) end |
#queues ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fairway/connection.rb', line 12 def queues @queues ||= begin scripts.registered_queues.map do |name, _| Queue.new(self, name) end end end |
#redis ⇒ Object
46 47 48 |
# File 'lib/fairway/connection.rb', line 46 def redis @config.redis end |
#register_queues ⇒ Object
36 37 38 39 40 |
# File 'lib/fairway/connection.rb', line 36 def register_queues @config.defined_queues.each do |queue| scripts.register_queue(queue.name, queue.channel) end end |
#scripts ⇒ Object
42 43 44 |
# File 'lib/fairway/connection.rb', line 42 def scripts @config.scripts end |
#subscribe(channel_pattern, &block) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fairway/connection.rb', line 28 def subscribe(channel_pattern, &block) redis.psubscribe(channel_pattern) do |on| on. do |pattern, channel, | block.call(channel, ) end end end |