Class: ConsulStockpile::WatchEventActor

Inherits:
Concurrent::Actor::RestartingContext
  • Object
show all
Defined in:
lib/consul_stockpile/watch_event_actor.rb

Instance Method Summary collapse

Constructor Details

#initialize(backup_actor:) ⇒ WatchEventActor

Returns a new instance of WatchEventActor.



7
8
9
10
# File 'lib/consul_stockpile/watch_event_actor.rb', line 7

def initialize(backup_actor:)
  @backup_actor = backup_actor
  tell :watch
end

Instance Method Details

#on_message(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/consul_stockpile/watch_event_actor.rb', line 12

def on_message(message)
  if message == :watch
    Logger.tagged('WatchEvent') do
      begin
        WatchEvent.call(
          handler: ->(event){ @backup_actor << :backup }
        )
      rescue => e
        Logger.warn "Warning: #{e.message}; retrying in 5 seconds"
        Logger.warn e.backtrace
        Concurrent::ScheduledTask.execute(5){ tell :watch }
      end
    end
  else
    pass
  end
end