Search code examples
ruby-on-railsherokudelayed-job

How to temporarily store files on heroku for delayed job import


I have an import functionality in my rails app that imports a CSV file and updates records accordingly. As this file gets bigger, the request takes longer and eventually times out. Therefore I chose to implement delayed_job to handle my long running requests. The only problem is, when the job runs, the error message Errno::ENOENT: No such file or directory is thrown. This is because my solution works with the CSV file in memory.

Is there a way to save the CSV file to my heroku server (and delete it after the import)?


Solution

  • Heroku's filesystems are ephemeral, i.e. content on them doesn't persist and they are not shared across dynos.

    If your delayed job is running on another dyno (which is how it should if it already isn't), you can not access the csv which exists on the disk of your web dyno.

    One workaround would be to create an action which serves the CSV. You could then use some HTTP library to download the CSV before the job starts.