在 Heroku 中创建临时文件 [英] Creating temporary files in Heroku

查看:30
本文介绍了在 Heroku 中创建临时文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在@Heroku 上托管了一个应用程序.该应用程序依赖于使用套接字侦听器获取的一些提要.套接字侦听器每秒获取一行 XML.检测到来自侦听器的文件结束信号后,我将文件上传到 Amazon S3 服务器.但是,在收到文件结束信号之前,是否可以将文件内容保存为 Heroku 中的临时文件?

I have an app hosted @ Heroku. The app depends on some feeds which are fetched using a socket listener. The socket listener gets one line of XML per second. Once I detect the end of file signal from the listener, I upload the file to Amazon S3 servers. But, until the end of file signal is received, is it possible to save the file content as a temporary file in Heroku?

推荐答案

您可以使用 #{RAILS_ROOT}/tmp/ 目录Rails.root.join('tmp').to_s:

阿斯彭&竹子
[...]
有两个可写目录:./tmp./log(在您的应用程序根目录下).
[...]

Aspen & Bamboo
[...]
There are two directories that are writeable: ./tmp and ./log (under your application root).
[...]

雪松
Cedar 提供了一个临时的可写文件系统.你可以在任何你想要的地方写出到磁盘.您的更改将在 dyno 重新启动和启动时丢失.

Cedar
Cedar offers an ephemeral writeable filesystem. You can write out to disk anywhere you would like. Your changes will be lost on dyno restart and spin-up.

RAILS_ROOT 适用于较旧的 Rails 版本,Rails.root 适用于较新的版本.

RAILS_ROOT is for older Rails versions, Rails.root is for newer versions.

当然,您不能依赖任何跨请求幸存的东西,不能保证您甚至会使用相同的测功机.

You can't depend on anything surviving across requests of course, there's no guarantee that you'll even be working with the same dyno.

只要你保持在同一个进程或请求中,Rails.root.join('tmp') 应该是可用的.如果您需要临时数据在请求或进程中存活,那么您最好使用其他东西(例如 MongoDB 或 PostgreSQL)作为收集数据到 S3 的地方.

As long as you stay within the same process or request, Rails.root.join('tmp') should be usable. If you need the temporary data to survive across requests or processes then you're better off using something else (such as MongoDB or PostgreSQL) as a collecting ground for your data on its way to S3.

感谢 Benjamin Wheeler 提供有关 RAILS_ROOTRails.root 更改.

Thanks to Benjamin Wheeler for the heads up about the RAILS_ROOT to Rails.root change.

这篇关于在 Heroku 中创建临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆