简体   繁体   English

如何使用耙任务在Heroku上保存文件?

[英]How to save a file on Heroku using a rake task?

I have a rake task to update some fields in the mongo db using mongoid. 我有一个rake任务,使用mongoid更新mongo db中的某些字段。 I use CSV.open to create a file to store the error for anomalies which can't be updated programatically. 我使用CSV.open创建一个文件来存储无法通过编程方式更新的异常的错误。 When I run this locally it simply creates the CSV file in the root directory of the app. 当我在本地运行时,它只是在应用程序的根目录中创建CSV文件。 But when I run rake on Heroku it doesn't seem to save the file anywhere I can access it. 但是,当我在Heroku上运行rake时,似乎没有将文件保存到我可以访问的任何位置。 Here's my code: 这是我的代码:

require 'csv'
CSV.open("errors.csv", "w") do |csv|
  csv << ["Email", "Jacket Size"]
  errors.each do |e|
    csv << e
  end
end

Heroku filesystem is read-only so your rake task cannot save this file in app root directory. Heroku文件系统是只读的,因此您的rake任务无法将此文件保存在应用程序根目录中。 With Heroku you can save only to /tmp and /log directories. 使用Heroku,您只能保存到/ tmp和/ log目录。 You can create your CSV file in /tmp directory and after it's processed you have to save it at some external storage (like Amazon S3) or send via mail, whatever you think is better in your case. 您可以在/ tmp目录中创建CSV文件,处理完后,您必须将其保存在某些外部存储设备(例如Amazon S3)中,或者通过邮件发送,无论您认为哪种情况更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM