class ScoutApm::LayawayFile

Attributes

context[R]
path[R]

Public Class Methods

new(context, path) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 7
def initialize(context, path)
  @path = path
  @context = context
end

Public Instance Methods

deserialize(data) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 39
def deserialize(data)
  Marshal.load(data)
end
load() click to toggle source
# File lib/scout_apm/layaway_file.rb, line 16
def load
  data = File.open(path, "r") { |f| read_raw(f) }
  deserialize(data)
rescue NameError, ArgumentError, TypeError => e
  # Marshal error
  logger.info("LayawayFile: Unable to load data")
  logger.debug("#{e.message}, #{e.backtrace.join("\n\t")}")
  nil
end
logger() click to toggle source
# File lib/scout_apm/layaway_file.rb, line 12
def logger
  context.logger
end
read_raw(f) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 43
def read_raw(f)
  contents = ""
  while true
    contents << f.read_nonblock(10_000)
  end
rescue Errno::EAGAIN, Errno::EINTR
  IO.select([f])
  retry
rescue EOFError
  contents
end
serialize(data) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 31
def serialize(data)
  Marshal.dump(data)
rescue
  ScoutApm::Agent.instance.logger.info("Failed Marshalling LayawayFile")
  ScoutApm::Agent.instance.logger.info(ScoutApm::Utils::MarshalLogging.new(data).dive) rescue nil
  raise
end
write(data) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 26
def write(data)
  serialized_data = serialize(data)
  File.open(path, "w") { |f| write_raw(f, serialized_data) }
end
write_raw(f, data) click to toggle source
# File lib/scout_apm/layaway_file.rb, line 55
def write_raw(f, data)
  result = 0
  while (result < data.length)
    result += f.write_nonblock(data)
  end
rescue Errno::EAGAIN, Errno::EINTR
  IO.select(nil, [f])
  retry
end