I use a similar idea, as in importing csv and excel Railscast , but since the standard code in this episode takes some time to process (uses ActiveRecord to create a new record for each line in the file). I get timeouts on Heroku and would like to move the import process to a background job.
I was unable to send the file variable (which is of type ActionDispatch :: Http :: UploadedFile), so instead I sent the separate variables file.original_filename and file.path
The job fails with an error file /var/folders/q3/xn0bp7yd2m56_4lbq0069jj80000gn/T/RackMultipart20150319-72431-1a4pnja.xlsx does not exist, which I believe is happening because the file was already deleted before the job started:
Downloaded files are temporary files whose lifespan is one request. When the object is complete, Ruby peels off the file, so there is no need to clean them with a separate maintenance task.
ActionDispatch :: Http :: UploadedFile
Can a file loaded with ActionDispatch :: Http :: UploadedFile not be used in background jobs?
I am using Rails 4.2, ActiveJob and Resque
source
share