Class: Eventr::Coordinator
- Inherits:
-
Object
- Object
- Eventr::Coordinator
- Includes:
- Singleton
- Defined in:
- lib/eventr/coordinator.rb
Instance Attribute Summary collapse
-
#consumers ⇒ Object
readonly
Returns the value of attribute consumers.
-
#publishers ⇒ Object
readonly
Returns the value of attribute publishers.
Class Method Summary collapse
Instance Method Summary collapse
- #consumer(queue_name, &block) ⇒ Object
-
#initialize ⇒ Coordinator
constructor
A new instance of Coordinator.
- #publisher(queue_name, &block) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Coordinator
28 29 30 31 |
# File 'lib/eventr/coordinator.rb', line 28 def initialize @publishers = {} @consumers = {} end |
Instance Attribute Details
#consumers ⇒ Object (readonly)
Returns the value of attribute consumers.
26 27 28 |
# File 'lib/eventr/coordinator.rb', line 26 def consumers @consumers end |
#publishers ⇒ Object (readonly)
Returns the value of attribute publishers.
26 27 28 |
# File 'lib/eventr/coordinator.rb', line 26 def publishers @publishers end |
Class Method Details
.method_missing(method, *args, &block) ⇒ Object
33 34 35 36 |
# File 'lib/eventr/coordinator.rb', line 33 def self.method_missing(method, *args, &block) return super unless self.instance.respond_to?(method) instance.public_send(method, *args, &block) end |
Instance Method Details
#consumer(queue_name, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/eventr/coordinator.rb', line 43 def consumer(queue_name, &block) raise InvalidQueue, "#{queue_name} queue does not exist. Define a publisher for the queue first." unless @publishers.include? queue_name @consumers[queue_name] ||= [] @consumers[queue_name] << Consumer.new(@publishers[queue_name], &block) end |
#publisher(queue_name, &block) ⇒ Object
38 39 40 41 |
# File 'lib/eventr/coordinator.rb', line 38 def publisher(queue_name, &block) raise InvalidQueue, "publisher already defined for queue '#{queue_name}'" if @publishers.include? queue_name @publishers[queue_name] = Publisher.new(&block) end |
#start ⇒ Object
49 50 51 52 53 54 |
# File 'lib/eventr/coordinator.rb', line 49 def start @publishers.each do |queue_name, _pubisher| _pubisher.start @consumers[queue_name].each { |c| c.start } end end |
#stop ⇒ Object
56 57 58 |
# File 'lib/eventr/coordinator.rb', line 56 def stop @publishers.each { |q, p| p.stop; @consumers[q].each { |c| c.stop } } end |