Class: EventHub::ActorHeartbeat

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Helper
Defined in:
lib/eventhub/actor_heartbeat.rb

Overview

Heartbeat class

Instance Method Summary collapse

Methods included from Helper

#create_bunny_connection, #get_name_from_class, #now_stamp, #stringify_keys

Constructor Details

#initialize(processor_instance) ⇒ ActorHeartbeat



10
11
12
13
# File 'lib/eventhub/actor_heartbeat.rb', line 10

def initialize(processor_instance)
  @processor_instance = processor_instance
  async.start
end

Instance Method Details

#cleanupObject



29
30
31
32
33
# File 'lib/eventhub/actor_heartbeat.rb', line 29

def cleanup
  EventHub.logger.info("Heartbeat is cleaning up...")
  publish(heartbeat(action: "stopped"))
  EventHub.logger.info("Heartbeat has sent a [stopped] beat")
end

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eventhub/actor_heartbeat.rb', line 15

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