简体   繁体   English

Heroku dyno没有写入档案

[英]Heroku dyno not writing to file

I have a bot running on Heroku. 我有一个在Heroku上运行的机器人。 This bot has some 'actions' that it is supposed to execute (those are dummies, just testing if everything is alright) and then write to file whatever action it did. 这个机器人有一些它应该执行的“动作”(那些是傻瓜,只是测试一切是否正常)然后写入文件,无论它做了什么动作。

The funny thing is that on my local machine, after 6-8 hours of testing I had 3 entries (3 actions performed), but on Heroku the bot has been running for a day now, and no entries are present (thought this was Heroku's issue, but with both cat and stat it shows that the file is empty). 有趣的是,在我的本地机器上,经过6-8小时的测试后,我有3个条目(执行了3个动作),但是在Heroku上,机器人已经运行了一天,并且没有条目存在(认为这是Heroku的问题,但是catstat都显示文件是空的)。

This is how I save the data to file: 这是我将数据保存到文件的方式:

 f = open('actions.txt', 'a')
 f.write(action)

Those are the file ( actions.txt ) permissions: 600 那些是文件( actions.txt )权限: 600

I just want to store the actions the bot performed over a week or so to make sure everything is working well. 我只想存储机器人执行一周左右的动作,以确保一切正常。

I just want to store the actions the bot performed over a week or so to make sure everything is working well 我只想存储机器人执行一周左右的动作,以确保一切正常

In that case you'll need a different approach to data persistence. 在这种情况下,您将需要一种不同的数据持久性方法。 Heroku's ephemeral filesystem loses whatever changes you make to it every time your dyno restarts, which happens at least once per day . 每次你的dyno重启时,Heroku的短暂文件系统都会丢失你所做的任何改变,每天至少发生一次

A simple solution might be to store your data in PostgreSQL, which Heroku supports out of the box . 一个简单的解决方案可能是将数据存储在PostgreSQL中, Heroku支持开箱即用 If you prefer other databases there are many to choose from . 如果你喜欢其他数据库也有很多选择

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

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