Class: Unleash::BackupFileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/unleash/backup_file_writer.rb

Class Method Summary collapse

Class Method Details

.save!(toggle_data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/unleash/backup_file_writer.rb', line 5

def self.save!(toggle_data)
  Unleash.logger.debug "Will save toggles to disk now"

  backup_file = Unleash.configuration.backup_file
  backup_file_tmp = "#{backup_file}.tmp-#{Process.pid}"

  File.open(backup_file_tmp, "w") do |file|
    file.write(toggle_data)
  end
  File.rename(backup_file_tmp, backup_file)
rescue StandardError => e
  # This is not really the end of the world. Swallowing the exception.
  Unleash.logger.error "Unable to save backup file. Exception thrown #{e.class}:'#{e}'"
  Unleash.logger.error "stacktrace: #{e.backtrace}"
end