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

Returns a new instance of ActorHeartbeat.



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

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

Instance Method Details

#cleanupObject



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

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

#startObject



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

def start
  EventHub.logger.info('Heartbeat is starting...')

  every(300) { 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)
    EventHub.logger.info('Heartbeat has sent a beat')
  end
end