class ScoutApm::LayawayFile
Attributes
Public Class Methods
Source
# File lib/scout_apm/layaway_file.rb, line 7 def initialize(context, path) @path = path @context = context end
Public Instance Methods
Source
# File lib/scout_apm/layaway_file.rb, line 39 def deserialize(data) Marshal.load(data) end
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
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
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
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
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