Class: Workling::Invokers::EventmachineSubscriber

Inherits:
Base
  • Object
show all
Defined in:
lib/workling/invokers/eventmachine_subscriber.rb

Instance Attribute Summary

Attributes inherited from Base

#reset_time, #sleep_time

Instance Method Summary collapse

Methods inherited from Base

#logger, #run

Constructor Details

#initialize(routing, client_class) ⇒ EventmachineSubscriber

Returns a new instance of EventmachineSubscriber.



10
11
12
# File 'lib/workling/invokers/eventmachine_subscriber.rb', line 10

def initialize(routing, client_class)
  super
end

Instance Method Details

#listenObject

Starts EM loop and sets up subscription callbacks for workers.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/workling/invokers/eventmachine_subscriber.rb', line 17

def listen
  EM.run do
    connect do
      routes.each do |route|
        @client.subscribe(route) do |args|
          begin
            run(route, args)
          rescue
            logger.error("EventmachineSubscriber listen error on #{route}: #{$!}")
          end
        end
      end
    end
  end
end

#stopObject



33
34
35
# File 'lib/workling/invokers/eventmachine_subscriber.rb', line 33

def stop
  EM.stop if EM.reactor_running?
end