Class: ConsulStockpile::BackupConsulKVActor

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

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, name:) ⇒ BackupConsulKVActor

Returns a new instance of BackupConsulKVActor.



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

def initialize(bucket:, name:)
  @bucket = bucket
  @name = name
end

Instance Method Details

#on_message(message) ⇒ Object



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

def on_message(message)
  if message == :backup
    Logger.tagged('Backup') do
      begin
        BackupConsulKV.call!(bucket: @bucket, name: @name)
      rescue => e
        Logger.warn "Warning: #{e.message}; retrying in 5 seconds"
        Logger.warn e.backtrace.join("\n")
        Concurrent::ScheduledTask.execute(5){ tell :backup }
      end
    end
    nil
  else
    pass
  end
end