Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - Roo "file does not exist" error when using Delayed Job
    primarykey
    data
    text
    <p>I'm using the Roo gem to import Excel files, CSV files, etc.</p> <p>The code works great a) on my local box with or without Delayed Job, and b) on Heroku without Delayed Job. Unfortunately when running on Heroku it fails if I'm using Delayed Job.</p> <p>Here are the details.</p> <p>Controller:</p> <pre><code>def importdo fileimport = Fileimport.new fileimport.file_name = params[:file].original_filename fileimport.file_path = params[:file].path fileimport.save fileimportid = fileimport.id Building.delay.import(fileimportid) redirect_to buildings_path, notice: "Buildings import started . . . you will receive an email upon completion." end </code></pre> <p><code>fileimport</code> is just a table I use to keep track of the filename and filepath (I tried to pass these as params but DelayedJob would always have problems when trying to convert the hash to YAML, so I just pass in the record ID instead). This also gives me the benefit of keeping track of my importing in a table.</p> <p>Here is my import class method:</p> <pre><code>def self.import(fileimportid) fileimport = Fileimport.find(fileimportid) file_name = fileimport.file_name file_path = fileimport.file_path newcount = 0 updatecount = 0 updating = false Building.acts_as_gmappable :process_geocoding =&gt; false spreadsheet = open_spreadsheet(file_name, file_path) header = spreadsheet.row(1) (2..spreadsheet.last_row).each do |i| row = Hash[[header, spreadsheet.row(i)].transpose] if zip = row["zip"].to_i.to_s if zip.length &gt; 5 zip = zip.first(5) end else raise "zip not valid" end if building = find_by_address_and_zip(row["address"], zip) updating = true else building = Building.new end #building.name = row["name"] building.zip = zip building.address = row["address"] building.city = row["city"] building.save! if updating updatecount += 1 else newcount += 1 end updating=false end Building.acts_as_gmappable :process_geocoding =&gt; true subject = "Your Building Import Completed Successfully!" body = "Your Building Import completed successfully!\n\n" + newcount.to_s + " buildings were created.\n" + updatecount.to_s + " buildings were updated." require 'rest_client' RestClient.post MAILGUN_API_URL+"/messages", :from =&gt; "obfuscated", :to =&gt; "obfuscated", :subject =&gt; subject, :text =&gt; body end def self.open_spreadsheet(file_name, file_path) case File.extname(file_name) when ".csv" then Roo::Csv.new(file_path, nil, :ignore) when ".xls" then Roo::Excel.new(file_path, nil, :ignore) when ".xlsx" then Roo::Excelx.new(file_path, nil, :ignore) else raise "Unknown file type: #{file_name}" end end </code></pre> <p>Here is my form for the file input:</p> <pre><code>&lt;% provide(:title, 'Import Buildings') %&gt; &lt;div class="row"&gt; &lt;aside class="span4"&gt; &lt;section&gt; &lt;h1&gt; Import Products &lt;/h1&gt; &lt;%= form_tag importdo_buildings_path, multipart: true do %&gt; &lt;%= file_field_tag :file %&gt; &lt;%= submit_tag "Import" %&gt; &lt;% end %&gt; &lt;/section&gt; &lt;/aside&gt; &lt;/div&gt; </code></pre> <p>The route looks like this:</p> <pre><code>resources :buildings do collection { post :importdo } end </code></pre> <p>Anyway, like I said, works great on my box (both with and without delayed job). Only works on Heroku without delayed job (i.e. I have to take out .delay). Here is the specific error I'm getting (the errors are emailed to me, I use an observer to check when Delayed::Job saves a record and check for last_error):</p> <pre><code>file /tmp/RackMultipart20130516-13-7li3o7 does not exist /app/vendor/bundle/ruby/1.9.1/gems/roo-1.11.2/lib/roo/excel.rb:26:in `block in initialize' /app/vendor/bundle/ruby/1.9.1/gems/roo-1.11.2/lib/roo/generic_spreadsheet.rb:579:in `block in make_tmpdir' /app/vendor/ruby-1.9.3/lib/ruby/1.9.1/tmpdir.rb:83:in `mktmpdir' /app/vendor/bundle/ruby/1.9.1/gems/roo-1.11.2/lib/roo/generic_spreadsheet.rb:578:in `make_tmpdir' /app/vendor/bundle/ruby/1.9.1/gems/roo-1.11.2/lib/roo/excel.rb:19:in `initialize' /app/app/models/building.rb:84:in `new' /app/app/models/building.rb:84:in `open_spreadsheet' /app/app/models/building.rb:39:in `import' </code></pre> <p>My initial thought was that it just a Heroku filesystem thing, but then I would think it wouldn't work without delayed_job either. My other thought is that because it is asynchronous maybe it is a timing issue (maybe the temp file either isn't there yet or isn't there anymore).</p> <p>Any ideas are greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload