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

查看:124
本文介绍了在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


Aspen& Bamboo

[...]

有两个可写的目录: ./ tmp ./log (在您的应用程序根目录下)。
[...]

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

< > Cedar 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.

你不能依赖任何存活当然,当然也不能保证你甚至可以使用同一个dyno。

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_ROOT Rails.root 更改。

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

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