Class: EventHub::ActorHeartbeat
- Inherits:
-
Object
- Object
- EventHub::ActorHeartbeat
- Includes:
- Celluloid, Helper
- Defined in:
- lib/eventhub/actor_heartbeat.rb
Overview
Heartbeat class
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize(processor_instance) ⇒ ActorHeartbeat
constructor
A new instance of ActorHeartbeat.
- #start ⇒ Object
Methods included from Helper
#bunny_connection_options, #create_bunny_connection, #get_name_from_class, #now_stamp, #stringify_keys
Constructor Details
#initialize(processor_instance) ⇒ ActorHeartbeat
Returns a new instance of ActorHeartbeat.
10 11 12 13 14 15 |
# File 'lib/eventhub/actor_heartbeat.rb', line 10 def initialize(processor_instance) @processor_instance = processor_instance @connection = nil @channel = nil async.start end |
Instance Method Details
#cleanup ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/eventhub/actor_heartbeat.rb', line 31 def cleanup EventHub.logger.info("Heartbeat is cleaning up...") begin publish(heartbeat(action: "stopped")) EventHub.logger.info("Heartbeat has sent a [stopped] beat") rescue => ex EventHub.logger.warn("Heartbeat cleanup publish: ignoring #{ex.class}: #{ex.}") end begin @channel&.close rescue => ex EventHub.logger.warn("Heartbeat cleanup channel: ignoring #{ex.class}: #{ex.}") end begin @connection&.close rescue => ex EventHub.logger.warn("Heartbeat cleanup connection: ignoring #{ex.class}: #{ex.}") end end |
#start ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/eventhub/actor_heartbeat.rb', line 17 def start cycle = Configuration.processor[:heartbeat_cycle_in_s] EventHub.logger.info("Heartbeat is starting [cycle: #{cycle}s]...") every(60 * 60 * 24) { EventHub.logger.info("Actual actors: #{Celluloid::Actor.all.size}: #{Celluloid::Actor.all.map { |a| a.class }.join(", ")}") } publish(heartbeat(action: "started")) EventHub.logger.info("Heartbeat has sent [started] beat") loop do sleep Configuration.processor[:heartbeat_cycle_in_s] publish(heartbeat) end end |