Builder occasionally generating invalid XML in Rails model

titosalah

New Member
I currently use Builder to generate the XML for my site's video player and Paperclip to save it to Amazon S3. The generation occurs in a before_save callback and the storage occurs during the save.\[code\]class VideoPlayerXml < ActiveRecord::Base has_attached_file :xml, :storage => :s3, .... def before_save .... File.open(file_path, "w+") do |file| x = Builder::XmlMarkup.new(:target => file, :indent => 1) x.instruct! end self.xml = File.open(file_path, "r") end ....end\[/code\]This saving process occurs in a background job as well. The issue I am having is that on very rare occasions, the XML generated by this process is invalid, missing entire or partial elements. When I reprocess a problem XML file, it is fine, so the problem is not reproducible. My first assumption was that a memory limitation could be causing this, but the last time this happened was this morning and the memory on that server has been fine the entire time. Any ideas what could be causing this? Thanks.
 
Back
Top